1515 default : next
1616
1717jobs :
18- get- version :
18+ version :
1919 runs-on : ubuntu-latest
2020 outputs :
21- version : ${{ steps.version.outputs.version }}
21+ tag : ${{ steps.version.outputs.version }}
2222 steps :
2323 - name : Checkout branch for release
2424 uses : actions/checkout@v4
2525
26- - name : Get tag version
26+ - name : Get tag version from package.json
2727 id : version
2828 run : |
29- if [ "${{ github.event.inputs.version }}" = "next" ]; then
30- CURR=$(jq -r .version package.json)
29+ INPUT_VERSION=${{ github.event.inputs.version }}
30+ if [ -z "$INPUT_VERSION" ]; then
31+ echo "::info:: No version input provided, defaulting to 'next'."
32+ INPUT_VERSION="next"
33+ fi
34+
35+ if [ $INPUT_VERSION = "next" ]; then
36+ CURR=$(jq -r .version composer.json)
3137 MAJOR=$(echo $CURR | cut -d. -f1)
3238 MINOR=$(echo $CURR | cut -d. -f2)
3339 PATCH=$(echo $CURR | cut -d. -f3)
3440 NEW_PATCH=$((PATCH+1))
3541 NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
36- echo "version= $NEW_VERSION" >> $GITHUB_OUTPUT
42+ VERSION=" $NEW_VERSION"
3743 else
38- echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
44+ VERSION="${{ github.event.inputs.version }}"
45+ fi
46+
47+ if [ -z "$VERSION" ]; then
48+ echo "::error::Version is empty. Failing job."
49+ exit 1
3950 fi
51+ echo "version=$VERSION" >> $GITHUB_OUTPUT
4052
4153 changelog :
42- needs : get-version
43- permissions :
44- contents : write
45- pull-requests : write
46- actions : read
47- models : read
48- uses : codesnippetspro/.github-private/.github/workflows/changelog.yml@v1
49- with :
50- repo : ${{ github.repository }}
51- branch : ${{ github.ref_name }}
52- tag : ${{ needs.get-version.outputs.version }}
53- secrets : inherit
54-
55-
56- git-push :
5754 runs-on : ubuntu-latest
58- needs : [get-version, changelog]
55+ needs : version
56+ strategy :
57+ matrix :
58+ include :
59+ - target-file : " CHANGELOG.md"
60+ template : " changelog"
61+ name : " github-changelog"
62+ - target-file : " src/readme.txt"
63+ template : " readme"
64+ name : " wordpress-readme"
5965 steps :
60- - name : Checkout branch for release
61- uses : actions/checkout@v4
62-
63- - name : Set up Node.js
64- uses : actions/setup-node@v4
65- with :
66- node-version-file : .node-version
67-
68- - name : Install Dependencies & Configure Git
69- run : |
70- npm install
71- git config user.name "code-snippets-bot"
72- git config user.email "sre@codesnippets.pro"
73-
74- - name : Create and switch to tag branch
66+ - name : Dispatch changelog generation
67+ env :
68+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
7569 run : |
76- git checkout -b "tag/v${{ needs.get-version.outputs.version }}"
70+
71+ if ! command -v gh &> /dev/null; then
72+ sudo apt update && sudo apt install -y gh
73+ fi
74+
75+ gh workflow run changelog.yml \
76+ --repo codesnippetspro/.github-private \
77+ --field repo="${{ github.repository }}" \
78+ --field branch="${{ github.ref_name }}" \
79+ --field version="${{ needs.version.outputs.tag }}" \
80+ --field template="${{ matrix.template }}" \
81+ --field target-file="./${{ matrix.target-file }}"
7782
78- - name : Commit changelog update
79- run : |
80- echo "${{ needs.changelog.outputs.patch }}" | git apply -
81- git ls-files --others --modified --exclude-standard | xargs git add
82- git add -u
83- git commit -m "chore(changelog): v${{ needs.get-version.outputs.version }}"
84-
85- - name : Commit version update
86- run : |
87- npm --no-git-tag-version version ${{ needs.get-version.outputs.version }}
88- git ls-files --others --modified --exclude-standard | xargs git add
89- git add -u
90- git commit -m "chore(tag): v${{ needs.get-version.outputs.version }}"
91-
92- - name : " Push to branch `tag/v${{ needs.get-version.outputs.version }}`"
93- run : |
94- git push --set-upstream origin "tag/v${{ needs.get-version.outputs.version }}"
95-
96- - name : " Open pull request: chore(release): `v${{ needs.get-version.outputs.version }}`"
83+ - name : Monitor workflow execution
9784 env :
98- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
85+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
9986 run : |
100- gh pr create --title 'chore(release): `v${{ needs.get-version.outputs.version }}`' --body 'Release `v${{ needs.get-version.outputs.version }}`' --base main --head "tag/v${{ needs.get-version.outputs.version }}"
87+ workflow_name="${{ matrix.name }}"
88+ target_repo="codesnippetspro/.github-private"
89+ max_attempts=30 # Maximum 5 minutes (30 * 10 seconds)
90+ attempt=0
91+
92+ echo "Monitoring workflow: $workflow_name in repository: $target_repo"
93+
94+ # Check if the repository exists and is accessible
95+ if ! gh repo view "$target_repo" >/dev/null 2>&1; then
96+ echo "::warning::Repository $target_repo is not accessible or doesn't exist"
97+ echo "::warning::Skipping monitoring for workflow: $workflow_name"
98+ exit 0
99+ fi
100+
101+ while : ; do
102+ attempt=$((attempt + 1))
103+
104+ # Check if we've exceeded max attempts
105+ if [ $attempt -gt $max_attempts ]; then
106+ echo "::warning::Timeout reached after $max_attempts attempts. Workflow '$workflow_name' monitoring stopped."
107+ echo "::warning::This might be expected if testing locally or if the workflow doesn't exist yet."
108+ exit 0
109+ fi
110+
111+ # Get the latest run for this workflow with error handling
112+ if ! status=$(gh run list --workflow changelog.yml --limit 1 --json status -q '.[0].status' --repo "$target_repo" 2>/dev/null); then
113+ echo "::warning::Attempt $attempt/$max_attempts: Could not find workflow '$workflow_name' or no runs exist yet. Checking again..."
114+ sleep 10
115+ continue
116+ fi
117+
118+ if ! conclusion=$(gh run list --workflow changelog.yml --limit 1 --json conclusion -q '.[0].conclusion' --repo "$target_repo" 2>/dev/null); then
119+ echo "::warning::Attempt $attempt/$max_attempts: Could not get conclusion for workflow '$workflow_name'. Checking again..."
120+ sleep 10
121+ continue
122+ fi
123+
124+ if [ "$status" = "completed" ]; then
125+ if [ "$conclusion" != "success" ]; then
126+ echo "::error::Workflow $workflow_name failed with conclusion: $conclusion"
127+ exit 1
128+ fi
129+ echo "✅ Workflow $workflow_name completed successfully"
130+ break
131+ fi
132+
133+ echo "⏳ Attempt $attempt/$max_attempts: Workflow $workflow_name is still running (status: $status). Waiting..."
134+ sleep 10
135+ done
0 commit comments