chore(ENV:vre-swan-cern) rename script and re-add paths #605
This file contains hidden or 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: | |
| - main | |
| env: | |
| REGISTRY: ghcr.io | |
| jobs: | |
| build-matrix-from-changed-files: | |
| runs-on: ubuntu-latest # windows-latest || macos-latest | |
| name: Build matrix from directories 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: | | |
| declare -A seen_dirs | |
| environments=() | |
| for dir in ${{ steps.changed-files.outputs.all_changed_files }}; do | |
| echo "$dir was changed" | |
| # Extract top-level dir (e.g., from "foo/bar/file.txt" -> "foo") | |
| top_level_dir=$(echo "$dir" | cut -d'/' -f1) | |
| # Skip if it's already seen | |
| if [[ -n "${seen_dirs[$top_level_dir]}" ]]; then | |
| echo " - $top_level_dir already added, skipping" | |
| continue | |
| fi | |
| echo " - $top_level_dir is a new dir, adding it" | |
| seen_dirs[$top_level_dir]=1 | |
| environments+=("\"${top_level_dir}\"") | |
| done | |
| ENVS_LIST=`echo "[${environments[@]}]" | sed 's/ /,/g'` | |
| echo "environment_list=$ENVS_LIST" >> $GITHUB_OUTPUT | |
| 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 | |
| if: ${{ needs.build-matrix-from-changed-files.outputs.environment_list != '[]' }} | |
| 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') |