release #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: release | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 20 * * *' | |
env: | |
APP_NAME: ollama | |
REPO_NAME: ollama/ollama | |
jobs: | |
check: | |
runs-on: ubuntu-latest | |
outputs: | |
APP_VERSION: ${{ steps.get-version.outputs.APP_VERSION }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: docker/setup-buildx-action@v3 | |
- name: Get Version | |
id: get-version | |
run: | | |
APP_VERSION=$(curl -s "https://api.github.com/repos/${{ env.REPO_NAME }}/releases/latest" | jq -r .tag_name) | |
if [ -z "${APP_VERSION}" ] || [ "${APP_VERSION}" == "null" ]; then | |
echo "Failed to get version" | |
exit 1 | |
fi | |
echo "APP_VERSION=${APP_VERSION}" >> $GITHUB_ENV | |
echo "APP_VERSION=${APP_VERSION}" >> $GITHUB_OUTPUT | |
echo "" | |
echo "========== Build Args ==========" | |
echo "APP_VERSION=${APP_VERSION}" | |
- name: Check Release | |
id: check-release | |
run: | | |
gh release view ${APP_VERSION} -R ${{ github.repository }} >/dev/null 2>&1 || echo "create=1" >> $GITHUB_OUTPUT | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create Tag | |
if : steps.check-release.outputs.create == '1' | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add . | |
git commit -m "Release ${APP_VERSION}" || true | |
git tag ${APP_VERSION} || true | |
git push origin ${APP_VERSION} || true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create Release | |
if : steps.check-release.outputs.create == '1' | |
run: | | |
gh release create ${APP_VERSION} -R ${{ github.repository }} --title ${APP_VERSION} --notes "**Full Changelog**: [${APP_VERSION}](https://github.com/${{ env.REPO_NAME }}/releases/tag/${APP_VERSION})" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
build: | |
runs-on: ubuntu-latest | |
needs: check | |
env: | |
APP_VERSION: ${{ needs.check.outputs.APP_VERSION }} | |
steps: | |
- name: Get Version | |
run: | | |
echo "VERSION=${VERSION}" | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ env.APP_VERSION }} | |
- uses: docker/setup-buildx-action@v3 | |
- name: Check Release | |
id: create-binaries | |
run: | | |
gh release view ${{ env.APP_VERSION }} -R ${{ github.repository }} | grep ${{ env.APP_NAME }}-linux-loong64.tgz >/dev/null 2>&1 || echo "create=1" >> $GITHUB_OUTPUT | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup QEMU | |
if : steps.create-binaries.outputs.create == '1' | |
run: docker run --rm --privileged ghcr.io/loong64/qemu-user-static --reset -p yes | |
- name: Login to GitHub Container Registry | |
if : steps.create-binaries.outputs.create == '1' | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/cache@v4 | |
if : steps.create-binaries.outputs.create == '1' | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-${{ env.APP_NAME }}-${{ env.APP_VERSION }} | |
restore-keys: ${{ runner.os }}-${{ env.APP_NAME }}- | |
- name: Build Binaries | |
if : steps.create-binaries.outputs.create == '1' | |
run: | | |
docker buildx build --platform linux/loong64 --build-arg APP_VERSION=${{ env.APP_VERSION }} -t ${{ env.APP_NAME }}-static-loong64:${{ env.APP_VERSION }} -f Dockerfile.cicd --cache-from type=local,src=/tmp/.buildx-cache --cache-to type=local,dest=/tmp/.buildx-cache-new,mode=max . --load | |
- name: Upgrade Release | |
if : steps.create-binaries.outputs.create == '1' | |
run: | | |
docker run --rm -v $(pwd)/dist:/dist ${{ env.APP_NAME }}-static-loong64:${{ env.APP_VERSION }} | |
ls -al dist | |
gh release upload ${{ env.APP_VERSION }} -R ${{ github.repository }} dist/* | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push image | |
if : steps.create-binaries.outputs.create == '1' | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
platforms: linux/loong64 | |
push: true | |
build-args: | | |
VERSION=${{ env.APP_VERSION }} | |
tags: | | |
ghcr.io/${{ github.repository_owner }}/${{ env.APP_NAME }}:latest | |
ghcr.io/${{ github.repository_owner }}/${{ env.APP_NAME }}:${{ env.APP_VERSION }} | |
outputs: type=image,oci-mediatypes=true,compression=zstd,compression-level=3,force-compression=true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Move cache | |
if : always() && steps.create-binaries.outputs.create == '1' | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |