Publish #28
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
name: Publish | |
on: | |
push: | |
branches: | |
- "main" | |
paths: | |
- "images/**/*" | |
# add workflow dispatch to manually publish the current images | |
workflow_dispatch: | |
pull_request: | |
paths: | |
- "images/**/*" | |
concurrency: | |
# Cancel in-progress jobs if a new job is trigged by a commit from the same branch | |
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
REGISTRY_IMAGE: friendsofredaxo/redaxo | |
jobs: | |
collect: | |
name: Collect images from directories | |
runs-on: ubuntu-latest | |
outputs: | |
IMAGES: ${{ steps.images.outputs.directories }} | |
steps: | |
- name: Checkout repository | |
# https://github.com/actions/checkout | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
- name: Collect images from directories | |
id: images | |
run: | | |
cd images | |
directories=$(tree -J -d -L 1 | jq -c '.[0].contents | map(.name)') | |
echo $directories | |
echo "directories=$directories" >> $GITHUB_OUTPUT | |
publish: | |
name: Publish | |
runs-on: ubuntu-latest | |
needs: [collect] | |
strategy: | |
fail-fast: false | |
matrix: | |
image: ${{ fromJson(needs.collect.outputs.IMAGES) }} | |
steps: | |
- name: Checkout repository | |
# https://github.com/marketplace/actions/checkout | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
- name: Create tag list for image | |
# We make use of yp (https://mikefarah.gitbook.io/yq/) to create a taglist from | |
# the image’s `tags.yml` file, where all given tags (like `5-stable`, `5-edge`) are | |
# combined with all image registries (like ghcr, Docker Hub). | |
run: | | |
taglist=$(yq 'map( | |
( | |
"friendsofredaxo/redaxo", | |
"ghcr.io/friendsofredaxo/redaxo" | |
) | |
+ ":" + .[]) | to_csv' ./images/${{ matrix.image }}/tags.yml) | |
echo "$taglist" | |
echo "TAGLIST=$taglist" >> $GITHUB_ENV | |
- name: Set up QEMU | |
# https://github.com/marketplace/actions/docker-setup-qemu | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
# https://github.com/marketplace/actions/docker-setup-buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
# https://github.com/marketplace/actions/docker-login | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to GitHub Container Registry | |
# https://github.com/marketplace/actions/docker-login | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push | |
# https://github.com/marketplace/actions/build-and-push-docker-images | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./images/${{ matrix.image }} | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
provenance: false | |
tags: ${{ env.TAGLIST }} | |
- name: Update repo description | |
# https://github.com/marketplace/actions/docker-hub-description | |
uses: peter-evans/dockerhub-description@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
repository: ${{ env.REGISTRY_IMAGE }} | |
short-description: ${{ github.event.repository.description }} | |
enable-url-completion: true | |
- name: Delete untagged containers from GitHub Container Registry | |
# https://github.com/marketplace/actions/delete-untagged-ghcr | |
uses: Chizkiyahu/delete-untagged-ghcr-action@v3 | |
with: | |
token: ${{ secrets.GH_PACKAGES }} | |
untagged_only: true | |
owner_type: org | |
except_untagged_multiplatform: true |