Skip to content

Commit

Permalink
Enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
cdivitotawela committed Nov 29, 2024
1 parent a842eb1 commit 569d379
Showing 4 changed files with 16 additions and 22 deletions.
27 changes: 7 additions & 20 deletions .github/workflows/dynamic-jobs.yaml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ jobs:
changes:
runs-on: ubuntu-latest
outputs:
folders: ${{ steps.folder-list.outputs.folders }}
folders: ${{ steps.changed-files.outputs.all_changed_files }}
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -20,28 +20,15 @@ jobs:
uses: tj-actions/changed-files@v45
id: changed-files
with:
dir_names: true
dir_names_max_depth: 2
json: true
matrix: true
files: |
dynamic-jobs/**
- name: Changed files
id: folder-list
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
echo "--- list of changed files ---"
echo "${{ env.ALL_CHANGED_FILES }}"
# We want the top level folder list as json string
# Json list is required to input to the matrix. Generate a json list and use that to
# get a list object in next job.
FOLDERS=$(echo "${{ env.ALL_CHANGED_FILES }}" | sed 's| |\n|g' | sed 's|^dynamic-jobs/\([^\/]*\).*|\1|g' | sort | uniq | jq -R -s -c 'split("\n")[:-1]')
echo $FOLDERS
# Set the job output. We have defined a job output in the job changes with matching key `folders`
echo "folders=$FOLDERS" >> "$GITHUB_OUTPUT"
execution:
name: "Execution [${{ matrix.folder }}]"
name: "Execution"
needs: [changes]
runs-on: ubuntu-latest
strategy:
@@ -53,4 +40,4 @@ jobs:
uses: actions/checkout@v4

- name: Execute
run: dynamic-jobs/${{ matrix.folder }}/runner.sh
run: ${{ matrix.folder }}/runner.sh
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -23,4 +23,10 @@ approval gates. Configure the environment in repository Settings -> Environments

Vulnerability scanning of container images using Trivy tool. Example [.github/workflows/security-scan.yaml](.github/workflows/security-scan.yaml).
In this workflow actions are pinned to git hash instead of tags. Tags can be moved but when pinned to git hash these are static.
This improves the security as intruder cannot move the tag to a vulnerability code.
This improves the security as intruder cannot move the tag to a vulnerability code.


## Generate Dynamic Jobs Based on File Changes

Sometimes it is essential to run jobs based on the files changed. Example [.github/workflows/dynamic-jobs.yaml](.github/workflows/dynamic-jobs.yaml)
runs create jobs and runs dynamically based on the changes to the folders.
1 change: 1 addition & 0 deletions dynamic-jobs/script1/runner.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash

echo "This dummy shell script id [1]"

2 changes: 1 addition & 1 deletion dynamic-jobs/script2/runner.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

echo "This dummy shell script id [2]"
echo "This dummy shell script id [2]"

0 comments on commit 569d379

Please sign in to comment.