step by step - 1 again 2 #146
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 automatic build and publish | |
on: | |
push: | |
branches: | |
- py311_wdf | |
env: | |
REGISTRY: ghcr.io | |
jobs: | |
build-matrix-from-changed-files: | |
runs-on: ubuntu-latest # windows-latest || macos-latest | |
name: Build matrix from directorues with changed files | |
steps: | |
- uses: actions/checkout@v3 | |
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/changed-files@v37 | |
with: | |
files_ignore: | | |
.github/** | |
**/README.md | |
LICENSE | |
*.md | |
dir_names: "true" | |
dir_names_exclude_current_dir: "true" | |
- name: List all changed dirs and create list with unique directories | |
id: set-matrix | |
run: | | |
environments=() | |
for dir in ${{ steps.changed-files.outputs.all_changed_files }}; do | |
echo "$dir was changed" | |
if [[ $(echo ${environments[@]} | fgrep -w ${dir}) ]]; then | |
echo " - ${dir} is in the list of changed dirs" | |
else | |
echo " - ${dir} is NOT in the list of changed dirs. Adding it!" | |
environments+=("\"${dir}\"") | |
echo " ** The update list is ${environments[@]}" | |
fi | |
done | |
ENVS_LIST=`echo "[${environments[@]}]" | sed 's/ /,/g'` | |
echo ::set-output name=environment_list::$ENVS_LIST | |
echo "The final list is: ${ENVS_LIST}" | |
outputs: | |
environment_list: ${{ steps.set-matrix.outputs.environment_list }} | |
build-and-push-image: | |
needs: build-matrix-from-changed-files | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
environments: ${{ fromJson(needs.build-matrix-from-changed-files.outputs.environment_list) }} | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Docker Checkout | |
uses: actions/checkout@v3 | |
- name: Log in to the GH Container Registry | |
id: login | |
uses: docker/[email protected] | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata for ${{ matrix.environments }} | |
id: meta | |
uses: docker/[email protected] | |
with: | |
flavor: | | |
latest=true | |
tags: | | |
type=sha | |
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.environments }} | |
- name: Build and push ${{ matrix.environments }} | |
id: build | |
uses: docker/[email protected] | |
with: | |
context: ./${{ matrix.environments }} | |
file: ./${{ matrix.environments }}/Dockerfile | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
build-args: | | |
BUILD_DATE=$(date +'%Y-%m-%dT%H:%M:%SZ') |