Skip to content

test first and second part of CI - 3 #4

test first and second part of CI - 3

test first and second part of CI - 3 #4

name: Docker automatic build and publish when changes in container dir
on:
push:
branches:
- ci_changes_in_containers
# pull_request:
# branches:
# - main
env:
REGISTRY: ghcr.io
jobs:
build-matrix-from-changed-dirs:
runs-on: ubuntu-latest
name: Build matrix from directories with changed files
outputs:
modified_container: ${{ steps.changed-files.outputs.all_changed_files }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2 # "0" (OR "2" -> To retrieve the preceding commit).
- name: Run changed-files with dir_names
id: changed-files
uses: tj-actions/[email protected]
with:
files_ignore: |
.github/**
infrastructure/**
.gitignore
*.md
*.png
LICENSE
**/README.md
dir_names: "true"
dir_names_exclude_current_dir: "true"
- name: List all changed dirs
run: |
for dir in ${{ steps.changed-files.outputs.all_changed_files }}; do
echo "$dir was changed"
done
build-and-push-changed-container:
needs: build-matrix-from-changed-dirs
runs-on: ubuntu-latest
strategy:
matrix:
containers: ${{ fromJson(needs.build-matrix-from-changed-dirs.outputs.modified_container) }}
permissions:
contents: read
packages: write
steps:
- name: Docker Checkout
uses: actions/checkout@v4
- name: Get tag
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Check env output
run: echo "tag" is ${{ env.RELEASE_VERSION }}
- name: Action for git describe
id: ghd
uses: proudust/gh-describe@v1
- name: Log in to the GH Container Registry
id: login
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for ${{ matrix.containers }}
id: metadata
uses: docker/[email protected]
with:
flavor: |
latest=true
tags: |
type=raw,value=${{ steps.ghd.outputs.tag }}-${{ steps.ghd.outputs.distance }}-${{ steps.ghd.outputs.sha }}
# ghcr.io/vre-hub/{vre}-{container_name}:{tag}
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ github.event.repository.name }}-${{ matrix.containers }}
# - name: Build and push ${{ matrix.containers }}
# id: build
# uses: docker/[email protected]
# with:
# context: ${{ matrix.containers }}
# file: ${{ matrix.containers }}/Dockerfile
# push: true
# tags: ${{ steps.metadata.outputs.tags }}
# labels: ${{ steps.metadata.outputs.labels }}
# build-args: |
# BUILD_DATE=$(date +'%Y-%m-%dT%H:%M:%SZ')
# TAG=${{ env.RELEASE_VERSION }}