Skip to content

Commit 2f04037

Browse files
fix: Fix notify action (#471)
* fix: Fix notify action Signed-off-by: Evgeniy Dikevich <[email protected]>
1 parent d7d7cfe commit 2f04037

File tree

2 files changed

+109
-66
lines changed

2 files changed

+109
-66
lines changed

.github/workflows/update-catalyst-ci-deps.yml

Lines changed: 18 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,75 +5,27 @@ on:
55
types: [published, edited]
66
workflow_dispatch:
77
inputs:
8-
dry_run:
9-
description: "Run in dry-run mode (no PRs created)"
10-
type: boolean
11-
default: false
8+
notify_type:
9+
description: "Notification type: Issue or PR"
10+
type: choice
11+
options:
12+
- "pr"
13+
- "issue"
14+
default: "pr"
15+
repos:
16+
description: "Comma separated list of repositories"
17+
type: string
18+
default: ""
1219

1320
permissions:
1421
contents: write
1522
pull-requests: write
23+
issues: write
1624

1725
jobs:
18-
notify-dependents:
19-
runs-on: ubuntu-latest
20-
steps:
21-
- name: Get release info
22-
id: release_info
23-
run: |
24-
if [ "${{ github.event_name }}" = "release" ]; then
25-
echo "tag_name=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
26-
echo "release_url=${{ github.event.release.html_url }}" >> $GITHUB_OUTPUT
27-
echo "release_notes=${{ github.event.release.body }}" >> $GITHUB_OUTPUT
28-
else
29-
# For manual dispatch, use latest release
30-
LATEST_TAG=$(git describe --tags --abbrev=0)
31-
echo "tag_name=$LATEST_TAG" >> $GITHUB_OUTPUT
32-
echo "release_url=https://github.com/${{ github.repository }}/releases/latest" >> $GITHUB_OUTPUT
33-
echo "release_notes=Manual dispatch" >> $GITHUB_OUTPUT
34-
fi
35-
36-
- name: Create PRs for dependent repositories
37-
env:
38-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39-
DRY_RUN: ${{ inputs.dry_run }}
40-
RELEASE_TAG: ${{ steps.release_info.outputs.tag_name }}
41-
RELEASE_URL: ${{ steps.release_info.outputs.release_url }}
42-
RELEASE_NOTES: ${{ steps.release_info.outputs.release_notes }}
43-
run: |
44-
REPOS=(
45-
"input-output-hk/catalyst-voices"
46-
"input-output-hk/hermes"
47-
"input-output-hk/catalyst-libs"
48-
"input-output-hk/catalyst-reviews"
49-
"input-output-hk/catalyst-som"
50-
"input-output-hk/catalyst-execution"
51-
"input-output-hk/norns"
52-
)
53-
54-
for repo in "${REPOS[@]}"; do
55-
repo=$(echo "$repo" | tr -d ' ')
56-
if [ -n "$repo" ]; then
57-
echo "Processing $repo"
58-
59-
if [ "$DRY_RUN" = "true" ]; then
60-
echo "[DRY RUN] Would create PR for $repo"
61-
else
62-
branch_name="chore/update-catalyst-ci-to-$(echo $RELEASE_TAG | tr -d 'v')"
63-
64-
default_branch=$(gh api repos/$repo --jq '.default_branch')
65-
base_sha=$(gh api repos/$repo/branches/$default_branch --jq '.commit.sha')
66-
gh api repos/$repo/git/refs -f ref="refs/heads/$branch_name" -f sha="$base_sha"
67-
gh pr create \
68-
--repo "$repo" \
69-
--title "Update catalyst-ci to $RELEASE_TAG" \
70-
--body "Update catalyst-ci to $RELEASE_TAG. Release: $RELEASE_URL" \
71-
--head "$branch_name" \
72-
--base "$default_branch"
73-
74-
echo "Created PR for $repo"
75-
fi
76-
77-
sleep 2
78-
fi
79-
done
26+
update_ci_deps:
27+
uses: ./.github/workflows/update-catalyst-deps.yml
28+
with:
29+
notify_type: ${{ inputs.notify_type }}
30+
repos: ${{ inputs.repos != '' && inputs.repos ||'input-output-hk/catalyst-voices, input-output-hk/hermes, input-output-hk/catalyst-libs, input-output-hk/catalyst-reviews, input-output-hk/catalyst-som, input-output-hk/catalyst-execution, input-output-hk/norns' }}
31+
secrets: inherit
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Update Catalyst Deps
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
notify_type:
7+
description: "Notification type: Issue or PR"
8+
type: string
9+
default: "pr"
10+
repos:
11+
description: "Comma separated list of repositories"
12+
type: string
13+
default: ""
14+
15+
env:
16+
GITHUB_TOKEN: ${{ secrets.CI_BOT_TOKEN }}
17+
18+
jobs:
19+
notify-dependents:
20+
runs-on: ubuntu-latest
21+
outputs:
22+
matrix: ${{ steps.matrix.outputs.matrix }}
23+
tag_name: ${{ steps.release_info.outputs.tag_name }}
24+
release_url: ${{ steps.release_info.outputs.release_url }}
25+
steps:
26+
- name: Get release info
27+
id: release_info
28+
run: |
29+
echo "tag_name=$(gh release list -R ${{ github.repository }} --json name,isLatest --jq '.[] | select(.isLatest)|.name')" >> $GITHUB_OUTPUT
30+
echo "release_url=$(gh release view -R ${{ github.repository }} $tag_name --json url | jq -r .[])" >> $GITHUB_OUTPUT
31+
32+
- name: Generate repos matrix
33+
id: matrix
34+
run: |
35+
repos=${{ inputs.repos }}
36+
echo "matrix=$(echo -n "$repos" | sed 's/ //g' | jq -R -s -c 'split(",")')" >> $GITHUB_OUTPUT
37+
38+
39+
create-pr-or-issue:
40+
runs-on: ubuntu-latest
41+
needs: notify-dependents
42+
strategy:
43+
matrix:
44+
repo: ${{ fromJSON(needs.notify-dependents.outputs.matrix) }}
45+
steps:
46+
- uses: actions/checkout@v4
47+
with:
48+
repository: ${{ matrix.repo }}
49+
50+
- name: Create PR or Issue for dependent repository
51+
env:
52+
RELEASE_TAG: ${{ needs.notify-dependents.outputs.tag_name }}
53+
RELEASE_URL: ${{ needs.notify-dependents.outputs.release_url }}
54+
run: |
55+
set -e
56+
57+
UPDATED_REPO="github.com/${{ github.repository }}"
58+
REPO_NAME=$(echo ${{ github.repository }} | cut -d/ -f2)
59+
60+
git config --global user.name "github-actions[bot]"
61+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
62+
63+
if [ "${{ inputs.notify_type }}" == "pr" ]; then
64+
echo "Create PR in ${{ matrix.repo }}"
65+
branch_name="chore/update-$REPO_NAME-to-$RELEASE_TAG"
66+
default_branch=$(gh api repos/${{ matrix.repo }} --jq '.default_branch')
67+
git checkout -b $branch_name
68+
69+
find . -type f -name "Earthfile" -exec sed -i -E \
70+
"s|(IMPORT[[:space:]]+$UPDATED_REPO/(earthly/)?[^:]+:)v[0-9]+\.[0-9]+\.[0-9]+|\1$RELEASE_TAG|" {} +
71+
72+
git add .
73+
git commit -m "Update $REPO_NAME to $RELEASE_TAG"
74+
git push origin "$branch_name"
75+
76+
gh pr create \
77+
--repo "${{ matrix.repo }}" \
78+
--title "Update $REPO_NAME to $RELEASE_TAG" \
79+
--body "Update $REPO_NAME to $RELEASE_TAG. Release: $RELEASE_URL" \
80+
--head "$branch_name" \
81+
--base "$default_branch"
82+
83+
echo "PR created for ${{ matrix.repo }}"
84+
else
85+
echo "Create issue in ${{ matrix.repo }}"
86+
gh issue create \
87+
--repo "${{ matrix.repo }}" \
88+
--title "Update $REPO_NAME to $RELEASE_TAG" \
89+
--body "Update $REPO_NAME to $RELEASE_TAG. Release: $RELEASE_URL"
90+
echo "Issue created in ${{ matrix.repo }}"
91+
fi

0 commit comments

Comments
 (0)