Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/giant-lizards-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bump-mcms-tools": minor
---

add bump mcms tools composite action
95 changes: 1 addition & 94 deletions actions/bump-mcms-tools/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ runs:
- name: Check out
uses: actions/checkout@v4

- name: Install yq
uses: dcarbone/install-yq-action@3b5b9f8b5d98b7d7e4cf94337336e414a2d79a8b # v1.3.1
with:
version: v4

- name: Resolve latest tag
id: latest
shell: bash
Expand Down Expand Up @@ -72,92 +67,4 @@ runs:
LATEST: ${{ steps.latest.outputs.tag }}
PATTERN: ${{ inputs.action_uses_pattern }} # e.g. smartcontractkit/.github/actions/get-mcms-tools@
WORKFLOWS_REGEX: ${{ inputs.workflows_regex }}
run: |
set -Eeuo pipefail
IFS=$'\n\t'

changed=false

echo "::notice::Searching for steps using pattern: $PATTERN"
echo "::notice::Latest version to set: $LATEST"
echo "::notice::Workflows regex: $WORKFLOWS_REGEX"

# Find workflow files
mapfile -d '' files < <(find . -regextype posix-extended -regex "$WORKFLOWS_REGEX" -type f -print0 || true)
total=${#files[@]}
echo "::notice::Found $total potential workflow file(s)"
if [[ $total -eq 0 ]]; then
echo "::warning::No workflow files matched regex ($WORKFLOWS_REGEX)"
echo "changed=$changed" | tee -a "$GITHUB_OUTPUT"
exit 0
fi

for f in "${files[@]}"; do
echo "::group::Processing $f"

# Count steps that use the action
match_count=$(yq -r '
[
.jobs[]?.steps[]?
| select((.uses // "") | type == "!!str" and (.uses | test("^'"$PATTERN"'")))
] | length
' "$f")

if [[ "$match_count" -eq 0 ]]; then
echo "::notice::No steps using the action — skipping."
echo "::endgroup::"
continue
fi

# Count how many of those are NOT already at the latest version (missing or different)
diff_count=$(yq -r '
[
.jobs[]?.steps[]?
| select((.uses // "") | type == "!!str" and (.uses | test("^'"$PATTERN"'")))
| (.with.version // "") | select(. != "'"$LATEST"'")
] | length
' "$f")

# For visibility, list current distinct versions on matched steps
echo "::notice::Matched steps: $match_count"
echo "::notice::Current versions on matched steps:"
yq -r '
.jobs[]?.steps[]?
| select((.uses // "") | type == "!!str" and (.uses | test("^'"$PATTERN"'")))
| (.with.version // "<missing>")
' "$f" | sed 's/^/ - /'

if [[ "$diff_count" -eq 0 ]]; then
echo "::notice::↩️ All matched steps already at $LATEST — no update needed."
echo "::endgroup::"
continue
fi

before_hash=$(sha1sum "$f" | cut -d' ' -f1)

# Patch ONLY matched steps
yq -i '
(.jobs[]?.steps[]?
| select((.uses // "") | type == "!!str" and (.uses | test("^'"$PATTERN"'")))
| .with.version) = "'"$LATEST"'"
' "$f"

after_hash=$(sha1sum "$f" | cut -d' ' -f1)

if [[ "$before_hash" != "$after_hash" ]]; then
echo "::notice::✅ Updated $f → version set to $LATEST"
changed=true
else
echo "::notice::↩️ No change detected after patch (already up-to-date/normalized)."
fi

echo "::endgroup::"
done

if [[ "$changed" == "true" ]]; then
echo "::notice::Workflow(s) updated to $LATEST"
else
echo "::notice::All relevant workflows already at latest version ($LATEST)"
fi

echo "changed=$changed" | tee -a "$GITHUB_OUTPUT"
run: "${GITHUB_ACTION_PATH}/scripts/update-workflow-files.sh"
89 changes: 89 additions & 0 deletions actions/bump-mcms-tools/scripts/update-workflow-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env bash
set -Eeuo pipefail
IFS=$'\n\t'

changed=false

echo "::notice::Searching for steps using pattern: $PATTERN"
echo "::notice::Latest version to set: $LATEST"
echo "::notice::Workflows regex: $WORKFLOWS_REGEX"

# Find workflow files
mapfile -d '' files < <(find . -regextype posix-extended -regex "$WORKFLOWS_REGEX" -type f -print0 || true)
total=${#files[@]}
echo "::notice::Found $total potential workflow file(s)"
if [[ $total -eq 0 ]]; then
echo "::warning::No workflow files matched regex ($WORKFLOWS_REGEX)"
echo "changed=$changed" | tee -a "$GITHUB_OUTPUT"
exit 0
fi

for f in "${files[@]}"; do
echo "::group::Processing $f"

# Count steps that use the action
match_count=$(yq -r '
[
.jobs[]?.steps[]?
| select((.uses // "") | type == "!!str" and (.uses | test("^'"$PATTERN"'")))
] | length
' "$f")

if [[ "$match_count" -eq 0 ]]; then
echo "::notice::No steps using the action — skipping."
echo "::endgroup::"
continue
fi

# Count how many of those are NOT already at the latest version (missing or different)
diff_count=$(yq -r '
[
.jobs[]?.steps[]?
| select((.uses // "") | type == "!!str" and (.uses | test("^'"$PATTERN"'")))
| (.with.version // "") | select(. != "'"$LATEST"'")
] | length
' "$f")

# For visibility, list current distinct versions on matched steps
echo "::notice::Matched steps: $match_count"
echo "::notice::Current versions on matched steps:"
yq -r '
.jobs[]?.steps[]?
| select((.uses // "") | type == "!!str" and (.uses | test("^'"$PATTERN"'")))
| (.with.version // "<missing>")
' "$f" | sed 's/^/ - /'

if [[ "$diff_count" -eq 0 ]]; then
echo "::notice::↩️ All matched steps already at $LATEST — no update needed."
echo "::endgroup::"
continue
fi

before_hash=$(sha1sum "$f" | cut -d' ' -f1)

# Patch ONLY matched steps
yq -i '
(.jobs[]?.steps[]?
| select((.uses // "") | type == "!!str" and (.uses | test("^'"$PATTERN"'")))
| .with.version) = "'"$LATEST"'"
' "$f"

after_hash=$(sha1sum "$f" | cut -d' ' -f1)

if [[ "$before_hash" != "$after_hash" ]]; then
echo "::notice::✅ Updated $f → version set to $LATEST"
changed=true
else
echo "::notice::↩️ No change detected after patch (already up-to-date/normalized)."
fi

echo "::endgroup::"
done

if [[ "$changed" == "true" ]]; then
echo "::notice::Workflow(s) updated to $LATEST"
else
echo "::notice::All relevant workflows already at latest version ($LATEST)"
fi

echo "changed=$changed" | tee -a "$GITHUB_OUTPUT"
Loading