Update action.yml #32
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 Image Build and Push | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
paths: | |
- 'action.yml' | |
- 'draft_images/py-rocket-2/**' | |
- 'draft_images/coastwatch-qgis/**' | |
- 'draft_images/test/**' | |
env: | |
WATCHED_DIRECTORIES: | | |
draft_images/py-rocket-2 | |
draft_images/coastwatch-qgis | |
draft_images/test | |
jobs: | |
find-changes: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix_dirs: ${{ steps.find-changes.outputs.matrix_dirs }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 2 | |
- name: Find changed directories | |
id: find-changes | |
run: | | |
watched_dirs=$(echo "${WATCHED_DIRECTORIES}" | tr '\n' '|') | |
watched_dirs="${watched_dirs%|}" | |
dirs=$(git diff --name-only HEAD^ HEAD | grep -E "^(${watched_dirs})" | sed -E "s|^(${watched_dirs})(/.*)|\1|" | sort -u) | |
# dirs=$(git diff --name-only HEAD^ HEAD | grep -E "^(${watched_dirs})" | sed 's|/[^/]*$||' | sort -u) | |
if [ -z "$dirs" ]; then | |
echo "No changed directories" | |
echo "::set-output name=matrix_dirs::[]" # Set an empty array to handle no changes | |
exit 0 | |
fi | |
# Convert to JSON array for matrix strategy | |
matrix_dirs=$(echo "$dirs" | jq -R -s -c 'split("\n") | map(select(. != ""))') | |
echo "::set-output name=matrix_dirs::$matrix_dirs" | |
echo "Debugging: matrix_dirs output is $matrix_dirs" | |
# Build job using matrix | |
build: | |
runs-on: ubuntu-latest | |
needs: find-changes | |
if: needs.find-changes.outputs.matrix_dirs != '[]' # Only run if there are changed directories | |
strategy: | |
matrix: | |
dir: ${{ fromJson(needs.find-changes.outputs.matrix_dirs) }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Extract image name | |
id: extract-name | |
shell: bash | |
run: | | |
full_image_name="${{ github.event.repository.name }}/$(basename ${{ matrix.dir }})" | |
echo "image_name=$full_image_name" >> $GITHUB_ENV | |
echo "Full image name set to: $full_image_name" | |
- name: Use reusable action for each directory | |
uses: nmfs-opensci/container-images@main | |
with: | |
image_dir: ${{ matrix.dir }} | |
image_name: ${{ env.image_name }} | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |