chore(gh-actions): only use major version as version identifier #38
This file contains 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
# SPDX-FileCopyrightText: 2023 Frederik Zorn <federdaemn@mail.de> | |
# | |
# SPDX-License-Identifier: Apache-2.0 | |
name: 'Build and push anki-sync container' | |
# run workflow on every branch, only upload on main (allow manual trigger) | |
on: [push, pull_request, workflow_dispatch] | |
jobs: | |
build-push: | |
# only push branch main to registry | |
name: 'Build and push image' | |
# use ubuntu as runner | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v4 | |
- name: Setup yq | |
uses: mikefarah/yq@v4 | |
- name: Setup oras | |
uses: oras-project/setup-oras@v1 | |
- name: Login to GitHub Container Registry | |
uses: redhat-actions/podman-login@v1 | |
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' | |
with: | |
registry: ghcr.io | |
username: federdaemn | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Login to DockerHub | |
uses: redhat-actions/podman-login@v1 | |
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' | |
with: | |
registry: docker.io | |
username: federdaemn | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: Set outputs for later use | |
id: set-op | |
run: | | |
# extract version from ./values.yml | |
echo "anki-version=$(yq '.version.anki-version' ./values.yml)" \ | |
>> $GITHUB_OUTPUT | |
# get current date+time | |
echo "time=$(date --utc +'%FT%TZ')" >> $GITHUB_OUTPUT | |
# get current date+time docker tag compatible | |
echo "time-docker=$(date --utc +'%Y-%m-%dt%H-%M-%Sz')" >> $GITHUB_OUTPUT | |
- name: Build image | |
id: build_image | |
uses: redhat-actions/buildah-build@v2 | |
with: | |
# which containerfile to build from | |
containerfiles: | | |
./containerfile | |
# set labels to append to the image | |
labels: | | |
# opencontainer labels specified | |
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys | |
org.opencontainers.image.title=oci-anki-sync | |
org.opencontainers.image.description=Anki sync server (anki-sync-server) in a container | |
org.opencontainers.image.authors=Frederik Zorn <federdaemnmail.de> | |
org.opencontainers.image.created=${{ steps.set-op.outputs.time }} | |
org.opencontainers.image.version=${{ steps.set-op.outputs.anki-version }} | |
org.opencontainers.image.licenses=AGPL-3.0-or-later | |
org.opencontainers.image.url=https://github.com/federdaemn/oci-anki-sync | |
org.opencontainers.image.source=https://github.com/federdaemn/oci-anki-sync | |
# artfifacthub labels specified | |
# https://artifacthub.io/docs/topics/repositories/container-images/#image-metadata | |
io.artifacthub.package.readme-url=https://raw.githubusercontent.com/federdaemn/oci-anki-sync/main/README.md | |
io.artifacthub.package.maintainers=[{"name":"federdaemn","email":"federdaemn@mail.de"}] | |
io.artifacthub.package.keywords=anki,sync,server,anki-sync-server,anki-sync | |
io.artifacthub.package.logo-url=https://raw.githubusercontent.com/federdaemn/oci-anki-sync/main/imgs/anki/logo.png | |
io.artifacthub.package.alternative-locations=docker.io/federdaemn/oci-anki-sync | |
# build args to pass to the build | |
build-args: | | |
anki_version=${{ steps.set-op.outputs.anki-version }} | |
# tags to build the image with | |
tags: | | |
ghcr.io/federdaemn/oci-anki-sync:latest | |
ghcr.io/federdaemn/oci-anki-sync:${{ steps.set-op.outputs.anki-version }} | |
ghcr.io/federdaemn/oci-anki-sync:${{ steps.set-op.outputs.time-docker }} | |
docker.io/federdaemn/oci-anki-sync:latest | |
docker.io/federdaemn/oci-anki-sync:${{ steps.set-op.outputs.anki-version }} | |
docker.io/federdaemn/oci-anki-sync:${{ steps.set-op.outputs.time-docker }} | |
- name: Push image | |
uses: redhat-actions/push-to-registry@v2 | |
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main' | |
with: | |
tags: ${{ steps.build_image.outputs.tags }} | |
# use oras to push artifacthub metadata to ghcr.io | |
# source: https://artifacthub.io/docs/topics/repositories/container-images/#repository-metadata | |
- name: Push metadata | |
run: | | |
oras push \ | |
ghcr.io/federdaemn/oci-anki-sync:artifacthub.io \ | |
--config /dev/null:application/vnd.cncf.artifacthub.config.v1+yaml \ | |
artifacthub-repo.yml:application/vnd.cncf.artifacthub.repository-metadata.layer.v1.yaml |