Merge pull request #267 from NBISweden/devel #1
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: Build and publish Docker images | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "env/*/Dockerfile" | |
- "env/*/environment.yml" | |
env: | |
REGISTRY: ghcr.io | |
INCLUDE_DIR: "env/" | |
REPOSITORY: ${{ github.repository }} | |
jobs: | |
changed-directories: | |
name: Get last directory name of changed files | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.changed-files.outputs.all_changed_files }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get changed files | |
uses: tj-actions/changed-files@v45 | |
id: changed-files | |
with: | |
matrix: true | |
dir_names: true | |
path: ${{ env.INCLUDE_DIR }} | |
dir_names_include_files: ${{ env.INCLUDE_DIR }} | |
dir_names_exclude_current_dir: true | |
build-and-push-image: | |
name: Build and push Docker images | |
runs-on: ubuntu-latest | |
needs: changed-directories | |
strategy: | |
fail-fast: false | |
matrix: | |
name: ${{ fromJSON(needs.changed-directories.outputs.matrix) }} | |
platform: [linux/amd64] | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Extract metadata for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}/${{ matrix.name }} | |
tags: | | |
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} | |
type=ref,event=branch,enable=${{ !endsWith(github.ref, github.event.repository.default_branch) }} | |
flavor: | | |
latest=false | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: ${{ env.INCLUDE_DIR }}/${{ matrix.name }} | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
platforms: ${{ matrix.platform }} |