From 47d59d317d7ec9aae22a3a3e56d885adc0a40342 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Tue, 29 Aug 2023 10:16:36 +0800 Subject: [PATCH 01/10] ci: add version info ci part. --- .github/workflows/build.yml | 64 +++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2396ba6a..29313324 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,10 +24,32 @@ jobs: mkdir -p config pytest + version-info: + runs-on: ubuntu-latest + needs: [test] + steps: + - name: Normal Release + if: | + github.event_name == 'pull_request' && + github.event.pull_request.merged == true + run: | + echo "release = 1" >> $GITHUB_ENV + git config --local user.email " + git config --local user.name "github-actions" + git tag -a ${{ github.event.pull_request.title }} -m ${{ github.event.pull_request.body }} + git push origin ${{ github.event.pull_request.title }} + echo "version = ${{ github.event.pull_request.title }}" >> $GITHUB_ENV + - name: Dev Release + if: | + github.event_name == 'push' && + contains(github.ref, 'alpha') || + contains(github.ref, 'beta') + run: | + echo "release = 1" >> $GITHUB_ENV + echo "dev = 1" >> $GITHUB_ENV + echo "version = ${{ github.ref_name }}" >> $GITHUB_ENV + build-webui: - if: > - (github.event_name == 'pull_request') || - (github.event_name == 'push' && github.ref_type == 'tag' && (contains(github.ref, 'alpha') || contains(github.ref, 'beta'))) runs-on: ubuntu-latest needs: [test] strategy: @@ -56,6 +78,7 @@ jobs: cd webui && pnpm build - name: Upload artifact + if: ${{ env.release == 1 }} uses: actions/upload-artifact@v3 with: name: dist @@ -68,19 +91,12 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Create Version info + - name: Create Version info via tag + if: ${{ env.release == 1 }} working-directory: ./backend/src run: | - echo "VERSION = '$GITHUB_REF_NAME'" > module/__version__.py - - - name: Create Tag - if: ${{ github.pull_request.merged == true }} - id: create-tag - run: | - git config --local user.email " - git config --local user.name "github-actions" - git tag -a ${{ github.event.pull_request.title }} -m ${{ github.event.pull_request.body }} - git push origin ${{ github.event.pull_request.title }} + echo ${{ env.version }} + echo "VERSION = ${{ env.version }}" >> module/__version__.py - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -90,6 +106,7 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Docker metadata main + if: ${{ env.release == 1 }} || ${{ env.dev != 1 }} id: meta uses: docker/metadata-action@v4 with: @@ -97,11 +114,11 @@ jobs: estrellaxd/auto_bangumi ghcr.io/${{ github.repository }} tags: | - type=semver,pattern={{version}} + type=semver,pattern=${{ env.version }} type=raw,value=latest - name: Docker metadata dev - if: contains(github.ref, 'tags') && contains(github.ref, 'alpha') || contains(github.ref, 'beta') + if: ${{ env.dev == 1 }} id: meta-dev uses: docker/metadata-action@v4 with: @@ -109,18 +126,18 @@ jobs: estrellaxd/auto_bangumi:dev ghcr.io/${{ github.repository }} tags: | - type=raw,value=${{ github.ref_name }} + type=raw,value=${{ env.version }} type=raw,value=dev-latest - name: Login to DockerHub - if: ${{ github.event_name == 'push' }} + if: ${{ env.release == 1 }} uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - name: Login to ghcr.io - if: ${{ github.event_name == 'push' }} + if: ${{ env.release == 1 }} uses: docker/login-action@v2 with: registry: ghcr.io @@ -150,10 +167,9 @@ jobs: cache-to: type=gha, scope=${{ github.workflow }} release: - if: > - (github.event_name == 'pull_request' && github.event.pull_request.merged == true) || - (github.event_name == 'push' && contains(github.ref, 'tags')) + runs-on: ubuntu-latest + if: ${{ env.release == 1 }} needs: [build-docker] steps: - name: Checkout code @@ -170,7 +186,7 @@ jobs: cd webui && ls -al && tree && zip -r dist.zip dist - name: Generate Release - if: ${{ github.event_name == 'pull_request' && github.event.pull_request.merged == true }} + if: ${{ env.dev != 1 }} uses: softprops/action-gh-release@v1 with: tag_name: ${{ github.event.pull_request.title }} @@ -184,7 +200,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} - name: Generate dev Release - if: ${{ github.event_name == 'push' && contains(github.ref, 'alpha') || contains(github.ref, 'beta') }} + if: ${{ env.dev == 1 }} uses: softprops/action-gh-release@v1 with: tag_name: ${{ github.ref_name }} From 1637c7283466c9484ff329d0625d4269b67c8858 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Tue, 29 Aug 2023 10:40:36 +0800 Subject: [PATCH 02/10] ci: change to output. --- .github/workflows/build.yml | 54 +++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 29313324..9db04387 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,17 +28,25 @@ jobs: runs-on: ubuntu-latest needs: [test] steps: - - name: Normal Release + - name: Test + run: echo "Test" + with: + release: 0 + dev: 0 + version: "Test" + - name: Normal Release, generate tag. if: | github.event_name == 'pull_request' && github.event.pull_request.merged == true run: | - echo "release = 1" >> $GITHUB_ENV git config --local user.email " git config --local user.name "github-actions" git tag -a ${{ github.event.pull_request.title }} -m ${{ github.event.pull_request.body }} git push origin ${{ github.event.pull_request.title }} - echo "version = ${{ github.event.pull_request.title }}" >> $GITHUB_ENV + with: + release: 1 + dev: 0 + version: ${{ github.event.pull_request.title }} - name: Dev Release if: | github.event_name == 'push' && @@ -48,10 +56,18 @@ jobs: echo "release = 1" >> $GITHUB_ENV echo "dev = 1" >> $GITHUB_ENV echo "version = ${{ github.ref_name }}" >> $GITHUB_ENV + with: + release: 1 + dev: 1 + version: ${{ github.ref_name }} + outputs: + release: ${{ steps.version-info.outputs.release }} + dev: ${{ steps.version-info.outputs.dev }} + version: ${{ steps.version-info.outputs.version }} build-webui: runs-on: ubuntu-latest - needs: [test] + needs: [version-info] strategy: matrix: node-version: [18] @@ -78,7 +94,7 @@ jobs: cd webui && pnpm build - name: Upload artifact - if: ${{ env.release == 1 }} + if: ${{ needs.version-info.outputs.release == 1 }} uses: actions/upload-artifact@v3 with: name: dist @@ -86,17 +102,17 @@ jobs: build-docker: runs-on: ubuntu-latest - needs: [build-webui] + needs: [build-webui, version-info] steps: - name: Checkout uses: actions/checkout@v3 - name: Create Version info via tag - if: ${{ env.release == 1 }} + if: ${{ needs.version-info.outputs.release == 1 }} working-directory: ./backend/src run: | - echo ${{ env.version }} - echo "VERSION = ${{ env.version }}" >> module/__version__.py + echo ${{ needs.version-info.outputs.version }} + echo "VERSION = ${{ needs.version-info.outputs.version }}" >> config.py - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -106,7 +122,7 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Docker metadata main - if: ${{ env.release == 1 }} || ${{ env.dev != 1 }} + if: ${{ needs.version-info.outputs.release == 1 }} && ${{ needs.version-info.outputs.dev != 1 }} id: meta uses: docker/metadata-action@v4 with: @@ -114,11 +130,11 @@ jobs: estrellaxd/auto_bangumi ghcr.io/${{ github.repository }} tags: | - type=semver,pattern=${{ env.version }} + type=semver,pattern=${{ needs.version-info.outputs.version }} type=raw,value=latest - name: Docker metadata dev - if: ${{ env.dev == 1 }} + if: ${{ needs.version-info.outputs.dev == 1 }} id: meta-dev uses: docker/metadata-action@v4 with: @@ -126,18 +142,18 @@ jobs: estrellaxd/auto_bangumi:dev ghcr.io/${{ github.repository }} tags: | - type=raw,value=${{ env.version }} + type=raw,value=${{ needs.version-info.outputs.version }} type=raw,value=dev-latest - name: Login to DockerHub - if: ${{ env.release == 1 }} + if: ${{ needs.version-info.outputs.release == 1 }} uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - name: Login to ghcr.io - if: ${{ env.release == 1 }} + if: ${{ needs.version-info.outputs.release == 1 }} uses: docker/login-action@v2 with: registry: ghcr.io @@ -167,10 +183,8 @@ jobs: cache-to: type=gha, scope=${{ github.workflow }} release: - runs-on: ubuntu-latest - if: ${{ env.release == 1 }} - needs: [build-docker] + needs: [build-docker, build-webui, version-info] steps: - name: Checkout code uses: actions/checkout@v2 @@ -186,7 +200,7 @@ jobs: cd webui && ls -al && tree && zip -r dist.zip dist - name: Generate Release - if: ${{ env.dev != 1 }} + if: ${{ needs.version-info.outputs.release == 1 }} && ${{ needs.version-info.outputs.dev != 1 }} uses: softprops/action-gh-release@v1 with: tag_name: ${{ github.event.pull_request.title }} @@ -200,7 +214,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} - name: Generate dev Release - if: ${{ env.dev == 1 }} + if: ${{ needs.version-info.outputs.dev == 1 }} uses: softprops/action-gh-release@v1 with: tag_name: ${{ github.ref_name }} From 1d17cc38cb1e62b7ddbe8d6d3064366ce5316b0f Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Tue, 29 Aug 2023 10:48:03 +0800 Subject: [PATCH 03/10] ci:fix uses. --- .github/workflows/build.yml | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9db04387..a8868271 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,37 +29,32 @@ jobs: needs: [test] steps: - name: Test - run: echo "Test" - with: - release: 0 - dev: 0 - version: "Test" + run: + echo ::set-output name=release::0 + echo ::set-output name=dev::0 + echo ::set-output name=version::Test - name: Normal Release, generate tag. if: | github.event_name == 'pull_request' && github.event.pull_request.merged == true run: | - git config --local user.email " + git config --local user.email git config --local user.name "github-actions" git tag -a ${{ github.event.pull_request.title }} -m ${{ github.event.pull_request.body }} git push origin ${{ github.event.pull_request.title }} - with: - release: 1 - dev: 0 - version: ${{ github.event.pull_request.title }} + echo ::set-output name=release::1 + echo ::set-output name=dev::0 + echo ::set-output name=version::${{ github.event.pull_request.title }} + - name: Dev Release if: | github.event_name == 'push' && contains(github.ref, 'alpha') || contains(github.ref, 'beta') run: | - echo "release = 1" >> $GITHUB_ENV - echo "dev = 1" >> $GITHUB_ENV - echo "version = ${{ github.ref_name }}" >> $GITHUB_ENV - with: - release: 1 - dev: 1 - version: ${{ github.ref_name }} + echo ::set-output name=release::1 + echo ::set-output name=dev::1 + echo ::set-output name=version::${{ github.ref_name }} outputs: release: ${{ steps.version-info.outputs.release }} dev: ${{ steps.version-info.outputs.dev }} From 04755775150179b94b4372e28a6ec53b1703d213 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Tue, 29 Aug 2023 10:54:02 +0800 Subject: [PATCH 04/10] ci: fix outdate usage. --- .github/workflows/build.yml | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a8868271..7883859c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,10 +29,10 @@ jobs: needs: [test] steps: - name: Test - run: - echo ::set-output name=release::0 - echo ::set-output name=dev::0 - echo ::set-output name=version::Test + run: | + echo "release=1" >> $GITHUB_OUTPUT + echo "dev=0" >> $GITHUB_OUTPUT + echo "version=Test" >> $GITHUB_OUTPUT - name: Normal Release, generate tag. if: | github.event_name == 'pull_request' && @@ -42,9 +42,9 @@ jobs: git config --local user.name "github-actions" git tag -a ${{ github.event.pull_request.title }} -m ${{ github.event.pull_request.body }} git push origin ${{ github.event.pull_request.title }} - echo ::set-output name=release::1 - echo ::set-output name=dev::0 - echo ::set-output name=version::${{ github.event.pull_request.title }} + echo "release=1" >> $GITHUB_OUTPUT + echo "dev=0" >> $GITHUB_OUTPUT + echo "version=${{ github.event.pull_request.title }}" >> $GITHUB_OUTPUT - name: Dev Release if: | @@ -52,9 +52,9 @@ jobs: contains(github.ref, 'alpha') || contains(github.ref, 'beta') run: | - echo ::set-output name=release::1 - echo ::set-output name=dev::1 - echo ::set-output name=version::${{ github.ref_name }} + echo "release=1" >> $GITHUB_OUTPUT + echo "dev=1" >> $GITHUB_OUTPUT + echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT outputs: release: ${{ steps.version-info.outputs.release }} dev: ${{ steps.version-info.outputs.dev }} @@ -156,15 +156,12 @@ jobs: password: ${{ secrets.ACCESS_TOKEN }} - name: Download artifact + if: ${{ needs.version-info.outputs.release == 1 }} uses: actions/download-artifact@v3 with: name: dist path: backend/src/dist - - name: View files - run: | - pwd && ls -al && tree - - name: Build and push uses: docker/build-push-action@v4 with: From cfcc2908a794241d068ea9a9cf7ef342c7900b07 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Tue, 29 Aug 2023 10:58:28 +0800 Subject: [PATCH 05/10] ci: fix bugs. --- .github/workflows/build.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7883859c..65839a7d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,7 +30,7 @@ jobs: steps: - name: Test run: | - echo "release=1" >> $GITHUB_OUTPUT + echo "release=0" >> $GITHUB_OUTPUT echo "dev=0" >> $GITHUB_OUTPUT echo "version=Test" >> $GITHUB_OUTPUT - name: Normal Release, generate tag. @@ -89,7 +89,6 @@ jobs: cd webui && pnpm build - name: Upload artifact - if: ${{ needs.version-info.outputs.release == 1 }} uses: actions/upload-artifact@v3 with: name: dist @@ -156,7 +155,6 @@ jobs: password: ${{ secrets.ACCESS_TOKEN }} - name: Download artifact - if: ${{ needs.version-info.outputs.release == 1 }} uses: actions/download-artifact@v3 with: name: dist From b402d974564458d388286dbbe1040a16c9f7f20c Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Tue, 29 Aug 2023 11:00:43 +0800 Subject: [PATCH 06/10] ci: remove outdated code. --- .github/workflows/build.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 65839a7d..d0b7f1a9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,7 +45,6 @@ jobs: echo "release=1" >> $GITHUB_OUTPUT echo "dev=0" >> $GITHUB_OUTPUT echo "version=${{ github.event.pull_request.title }}" >> $GITHUB_OUTPUT - - name: Dev Release if: | github.event_name == 'push' && @@ -177,7 +176,7 @@ jobs: needs: [build-docker, build-webui, version-info] steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Download artifact uses: actions/download-artifact@v3 From 7d58e3c4863ba7d6845b2ef2c2c2b5e15d9aa7d3 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Tue, 29 Aug 2023 11:07:55 +0800 Subject: [PATCH 07/10] ci: fix if. --- .github/workflows/build.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d0b7f1a9..a7be2dda 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -101,11 +101,10 @@ jobs: uses: actions/checkout@v3 - name: Create Version info via tag - if: ${{ needs.version-info.outputs.release == 1 }} working-directory: ./backend/src run: | echo ${{ needs.version-info.outputs.version }} - echo "VERSION = ${{ needs.version-info.outputs.version }}" >> config.py + echo "VERSION=${{ needs.version-info.outputs.version }}" >> module/__version__.py - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -115,7 +114,7 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Docker metadata main - if: ${{ needs.version-info.outputs.release == 1 }} && ${{ needs.version-info.outputs.dev != 1 }} + if: ${{ needs.version-info.outputs.release == 1 && needs.version-info.outputs.dev != 1 }} id: meta uses: docker/metadata-action@v4 with: @@ -189,7 +188,7 @@ jobs: cd webui && ls -al && tree && zip -r dist.zip dist - name: Generate Release - if: ${{ needs.version-info.outputs.release == 1 }} && ${{ needs.version-info.outputs.dev != 1 }} + if: ${{ needs.version-info.outputs.release == 1 && needs.version-info.outputs.dev != 1 }} uses: softprops/action-gh-release@v1 with: tag_name: ${{ github.event.pull_request.title }} From 0b6d0647d4f1c1f4647d8ac7ee79e63069b8148f Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Tue, 29 Aug 2023 11:15:07 +0800 Subject: [PATCH 08/10] fix: release bus. --- .github/workflows/build.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a7be2dda..c1843f2d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -173,6 +173,7 @@ jobs: release: runs-on: ubuntu-latest needs: [build-docker, build-webui, version-info] + if: ${{ needs.version-info.outputs.release == 1 }} steps: - name: Checkout code uses: actions/checkout@v3 @@ -217,7 +218,7 @@ jobs: telegram: runs-on: ubuntu-latest - needs: [release] + needs: [release, version-info] steps: - name: send telegram message on push uses: appleboy/telegram-action@master @@ -225,5 +226,5 @@ jobs: to: ${{ secrets.TELEGRAM_TO }} token: ${{ secrets.TELEGRAM_TOKEN }} message: | - New release: ${{ github.event.release.title }} - Link: ${{ github.event.release.html_url }} + New release: ${{ needs.version-info.outputs.version }} + Link: ${{ needs.release.outputs.url }} From f86d9ce67ae833481661a55ed5cf14f11edd7c6d Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Tue, 29 Aug 2023 11:25:26 +0800 Subject: [PATCH 09/10] ci: fix test. --- .github/workflows/build.yml | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c1843f2d..746e0aa7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -159,6 +159,7 @@ jobs: path: backend/src/dist - name: Build and push + if: ${{ needs.version-info.outputs.release == 1 && needs.version-info.outputs.dev != 1 }} uses: docker/build-push-action@v4 with: context: . @@ -170,6 +171,29 @@ jobs: cache-from: type=gha, scope=${{ github.workflow }} cache-to: type=gha, scope=${{ github.workflow }} + - name: Build and push dev + if: ${{ needs.version-info.outputs.dev == 1 }} + uses: docker/build-push-action@v4 + with: + context: . + builder: ${{ steps.buildx.output.name }} + platforms: linux/amd64,linux/arm64,linux/arm/v7 + push: ${{ github.event_name == 'push' }} + tags: ${{ steps.meta-dev.outputs.tags }} + labels: ${{ steps.meta-dev.outputs.labels }} + cache-from: type=gha, scope=${{ github.workflow }} + cache-to: type=gha, scope=${{ github.workflow }} + + - name: Build test + if: ${{ needs.version-info.outputs.release == 0 }} + uses: docker/build-push-action@v4 + with: + context: . + builder: ${{ steps.buildx.output.name }} + platforms: linux/amd64,linux/arm64,linux/arm/v7 + push: false + tags: estrellaxd/auto_bangumi:test + release: runs-on: ubuntu-latest needs: [build-docker, build-webui, version-info] @@ -189,7 +213,7 @@ jobs: cd webui && ls -al && tree && zip -r dist.zip dist - name: Generate Release - if: ${{ needs.version-info.outputs.release == 1 && needs.version-info.outputs.dev != 1 }} + if: ${{ needs.version-info.outputs.dev != 1 }} uses: softprops/action-gh-release@v1 with: tag_name: ${{ github.event.pull_request.title }} From 31ac5956cb0b7e820b6ea8204033d4caf6fea524 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Tue, 29 Aug 2023 11:33:11 +0800 Subject: [PATCH 10/10] ci: add cache in build test. --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 746e0aa7..af470a1f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -193,6 +193,8 @@ jobs: platforms: linux/amd64,linux/arm64,linux/arm/v7 push: false tags: estrellaxd/auto_bangumi:test + cache-from: type=gha, scope=${{ github.workflow }} + cache-to: type=gha, scope=${{ github.workflow }} release: runs-on: ubuntu-latest