Merge pull request #49 from biom262/popgen-wi24 #376
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: Docker | |
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
on: | |
push: | |
branches: [ "master", "wi24" ] | |
# Publish semver tags as releases. | |
tags: [ 'v*.*.*' ] | |
paths-ignore: | |
- 'README.md' | |
pull_request: | |
branches: [ "master", "wi24" ] | |
# Publish semver tags as releases. | |
tags: [ 'v*.*.*' ] | |
paths-ignore: | |
- 'README.md' | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
# adapted from https://docs.github.com/en/actions/learn-github-actions/expressions#example-returning-a-json-object | |
metadata: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.generate-matrix.outputs.matrix }} # contains a list of the module names encoded as json | |
modulenames: ${{ steps.generate-matrix.outputs.modulenames }} # contains a simple, space-separated list of the module names | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: generate matrix | |
id: generate-matrix | |
# adapted from https://stackoverflow.com/a/74829694 | |
run: | | |
modulenames="$(ls *.yml | sed 's/.yml//' | paste -s -d ' ')" | |
echo "modulenames=$modulenames" >> $GITHUB_OUTPUT | |
# echo $modulenames | tr ' ' '\n' | sed 's/^/type=gha,scope=builder-/' | paste -s | |
matrix=$(echo $modulenames | jq -R 'split(" ") | {include: map({modulename: .})}') | |
echo "matrix=$(echo $matrix | jq -c)" >> $GITHUB_OUTPUT | |
build-and-push-images: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
needs: [metadata] | |
strategy: | |
matrix: ${{ fromJson(needs.metadata.outputs.matrix) }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: prune | |
run: docker system prune -af | |
- name: Build and push Docker image | |
id: builder | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
file: Dockerfile | |
push: true | |
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.modulename }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
build-args: | | |
"modulename=${{ matrix.modulename }}" |