Build and push anki-sync-server Docker image #24
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 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: | |
# list of Docker images to use as base name for tags | |
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: Get tag | |
# id: tag | |
# uses: devops-actions/[email protected] | |
# with: | |
# strip_v: true # Optional: Remove 'v' character from version | |
- 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 }} |