diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2396ba6a..af470a1f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,12 +24,44 @@ jobs: mkdir -p config pytest - build-webui: - if: > - (github.event_name == 'pull_request') || - (github.event_name == 'push' && github.ref_type == 'tag' && (contains(github.ref, 'alpha') || contains(github.ref, 'beta'))) + version-info: runs-on: ubuntu-latest needs: [test] + steps: + - name: Test + run: | + echo "release=0" >> $GITHUB_OUTPUT + echo "dev=0" >> $GITHUB_OUTPUT + echo "version=Test" >> $GITHUB_OUTPUT + - 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.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 "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' && + contains(github.ref, 'alpha') || + contains(github.ref, 'beta') + run: | + 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 }} + version: ${{ steps.version-info.outputs.version }} + + build-webui: + runs-on: ubuntu-latest + needs: [version-info] strategy: matrix: node-version: [18] @@ -63,24 +95,16 @@ 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 + - name: Create Version info via tag 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 ${{ needs.version-info.outputs.version }} + echo "VERSION=${{ needs.version-info.outputs.version }}" >> module/__version__.py - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -90,6 +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 }} id: meta uses: docker/metadata-action@v4 with: @@ -97,11 +122,11 @@ jobs: estrellaxd/auto_bangumi ghcr.io/${{ github.repository }} tags: | - type=semver,pattern={{version}} + type=semver,pattern=${{ needs.version-info.outputs.version }} type=raw,value=latest - name: Docker metadata dev - if: contains(github.ref, 'tags') && contains(github.ref, 'alpha') || contains(github.ref, 'beta') + if: ${{ needs.version-info.outputs.dev == 1 }} id: meta-dev uses: docker/metadata-action@v4 with: @@ -109,18 +134,18 @@ jobs: estrellaxd/auto_bangumi:dev ghcr.io/${{ github.repository }} tags: | - type=raw,value=${{ github.ref_name }} + type=raw,value=${{ needs.version-info.outputs.version }} type=raw,value=dev-latest - name: Login to DockerHub - if: ${{ github.event_name == 'push' }} + 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: ${{ github.event_name == 'push' }} + if: ${{ needs.version-info.outputs.release == 1 }} uses: docker/login-action@v2 with: registry: ghcr.io @@ -133,11 +158,8 @@ jobs: name: dist path: backend/src/dist - - name: View files - run: | - pwd && ls -al && tree - - 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: . @@ -149,15 +171,38 @@ 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 + cache-from: type=gha, scope=${{ github.workflow }} + 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 - needs: [build-docker] + needs: [build-docker, build-webui, version-info] + if: ${{ needs.version-info.outputs.release == 1 }} steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Download artifact uses: actions/download-artifact@v3 @@ -170,7 +215,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: ${{ needs.version-info.outputs.dev != 1 }} uses: softprops/action-gh-release@v1 with: tag_name: ${{ github.event.pull_request.title }} @@ -184,7 +229,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: ${{ needs.version-info.outputs.dev == 1 }} uses: softprops/action-gh-release@v1 with: tag_name: ${{ github.ref_name }} @@ -199,7 +244,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 @@ -207,5 +252,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 }}