| name: Build and push anki-sync-server Docker image |
|
|
| on: |
| workflow_dispatch: |
| schedule: |
| - cron: "11 0 * * *" |
|
|
| concurrency: |
| group: ${{ github.workflow }}-${{ github.ref }} |
| cancel-in-progress: true |
|
|
| jobs: |
| get-latest-tag: |
| name: Get latest tag |
| runs-on: ubuntu-latest |
| steps: |
| - name: Checkout Anki |
| uses: actions/checkout@v4 |
| with: |
| fetch-depth: 0 |
| repository: ankitects/anki |
| - name: Get Anki latest tag |
| id: tag |
| run: echo "tag=$(git describe --tags `git rev-list --tags --max-count=1`)" >> "$GITHUB_OUTPUT" |
|
|
| - name: Checkout |
| uses: actions/checkout@v4 |
| with: |
| ref: ${{ github.head_ref }} |
| fetch-depth: 0 |
| - name: Get my latest tag |
| id: mytag |
| run: echo "mytag=$(git describe --tags `git rev-list --tags --max-count=1`)" >> "$GITHUB_OUTPUT" |
| - name: Add tag |
| id: addtag |
| if: steps.tag.outputs.tag != steps.mytag.outputs.mytag |
| run: | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| git config --local user.name "github-actions[bot]" |
| git tag ${{ steps.tag.outputs.tag }} |
| git push origin --tags |
| echo "addtag=true" >> "$GITHUB_OUTPUT" |
| |
| outputs: |
| tag: ${{ steps.tag.outputs.tag }} |
| addtag: ${{ steps.addtag.outputs.addtag }} |
|
|
| build-docker-image: |
| needs: get-latest-tag |
| if: needs.get-latest-tag.outputs.addtag == 'true' |
| runs-on: ubuntu-latest |
| steps: |
| - name: Checkout |
| uses: actions/checkout@v4 |
| with: |
| ref: ${{ needs.get-latest-tag.outputs.tag }} |
|
|
| - name: Docker meta |
| id: meta |
| uses: docker/metadata-action@v5 |
| with: |
| |
| images: | |
| ${{ secrets.DOCKER_USERNAME }}/anki-sync-server |
| ghcr.io/${{ github.repository_owner }}/anki-sync-server |
| tags: | |
| type=ref,event=tag |
| type=raw,value=${{ needs.get-latest-tag.outputs.tag }} |
| |
| - name: Set up QEMU |
| uses: docker/setup-qemu-action@v3 |
|
|
| - name: Set up Docker Buildx |
| uses: docker/setup-buildx-action@v3 |
|
|
| - name: Login to DockerHub |
| uses: docker/login-action@v3 |
| with: |
| username: ${{ secrets.DOCKER_USERNAME }} |
| password: ${{ secrets.DOCKER_PASSWORD }} |
|
|
| - name: Login to ghcr.io |
| uses: docker/login-action@v3 |
| with: |
| registry: ghcr.io |
| username: ${{ github.repository_owner }} |
| password: ${{ secrets.GH_PAT }} |
|
|
| |
| |
| |
| |
| |
|
|
| - name: Build and push Docker images to ghcr.io and DockerHub |
| uses: docker/build-push-action@v5 |
| with: |
| build-args: | |
| ANKI_VERSION=${{ needs.get-latest-tag.outputs.tag }} |
| context: . |
| file: ./Dockerfile |
| push: true |
| tags: ${{ steps.meta.outputs.tags }} |
| labels: ${{ steps.meta.outputs.labels }} |