Build and publish docker image on GitHub #35
This file contains hidden or 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: Build and publish docker image on GitHub | |
| on: | |
| push: | |
| branches: | |
| - master | |
| workflow_dispatch: | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Connect to GHRC | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Retrieve latest release version | |
| id: retrieve_latest_release_version | |
| run: | | |
| LATEST_RELEASE_VERSION=$(curl -s https://api.github.com/repos/ankitects/anki/releases/latest | jq -r '.tag_name') | |
| echo "latest_release_version=$LATEST_RELEASE_VERSION" >> $GITHUB_OUTPUT | |
| - name: Get metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=${{ steps.retrieve_latest_release_version.outputs.LATEST_RELEASE_VERSION }} | |
| type=raw,value=latest | |
| type=sha,enable=false | |
| - name: Build and push image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./Python.Dockerfile | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| - name: Upload new release version as artifacts | |
| run: | | |
| echo "${{ steps.retrieve_latest_release_version.outputs.LATEST_RELEASE_VERSION }}" > anki-release-version | |
| - name: Upload new artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: anki-release-version | |
| path: anki-release-version |