From 825006aa5126b8a9f0ea9d96f12c1048005036cc Mon Sep 17 00:00:00 2001 From: Jennings Zhang Date: Tue, 8 Oct 2024 13:12:45 -0400 Subject: [PATCH] Update GHA --- .github/workflows/build.yml | 54 ++++++++++++++----------------------- 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 30ac864..706e8c8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,39 +15,11 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install rye - uses: eifinger/setup-rye@d4c3ac7b15d8bf2e0b45e2d257c6b5cdbebc3643 # v4.2.1 + uses: eifinger/setup-rye@cba39b644640fb95c375ce5bfe2fdf33c0b815fc # v4.2.6 with: - version: '0.36.0' + version: '0.41.0' enable-cache: true cache-prefix: ${{ github.workflow }} - - name: Decide image tags - id: info - shell: python - run: | - import os - import itertools - - registries = ['docker.io', 'ghcr.io'] - repos = ['${{ github.repository }}'.lower()] - if '${{ github.ref_type }}' == 'branch': - tags = ['latest'] - elif '${{ github.ref_type }}' == 'tag': - version = '${{ github.ref_name }}'[1:] - tags = ['latest', version] - else: - tags = [] - - def join_tag(t): - registry, repo, tag = t - return f'{registry}/{repo}:{tag}' - - product = itertools.product(registries, repos, tags) - tags_csv = ','.join(map(join_tag, product)) - push = 'true' if len(tags) >= 2 else 'false' - - with open(os.environ['GITHUB_OUTPUT'], 'a') as out: - out.write(f'tags={tags_csv}\n') - out.write(f'push={push}\n') - name: Set version run: | if [ '${{ github.ref_type }}' = 'tag' ]; then @@ -59,15 +31,28 @@ jobs: rye version > src/serie/version.txt - name: Build Python wheel run: rye build --wheel --clean + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + docker.io/${{ github.repository }} + ghcr.io/${{ github.repository }} + tags: | + type=pep440,pattern={{version}} + type=pep440,pattern={{major}}.{{minor}} + type=raw,value=latest,enable={{is_default_branch}} + - uses: docker/setup-qemu-action@v3 - uses: docker/setup-buildx-action@v3 - name: Login to DockerHub - if: github.event_name == 'push' id: dockerhub_login + if: github.event_name == 'push' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} - name: Login to GitHub Container Registry + id: ghcr_login if: github.event_name == 'push' uses: docker/login-action@v3 with: @@ -79,11 +64,12 @@ jobs: with: context: . platforms: linux/amd64,linux/arm64 - tags: ${{ steps.info.outputs.tags }} - push: ${{ steps.info.outputs.push }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + push: ${{ steps.dockerhub_login.outcome == 'success' && steps.ghcr_login.outcome == 'success' }} - name: Update DockerHub description uses: peter-evans/dockerhub-description@v4 - if: ${{ steps.info.outputs.push }} + if: ${{ steps.dockerhub_login.outcome == 'success' }} with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }}