Skip to content

Commit 8e9dd73

Browse files
GHA-221 Improve automated-release with features required by cloud-security (#124)
1 parent 536f755 commit 8e9dd73

File tree

1 file changed

+81
-4
lines changed

1 file changed

+81
-4
lines changed

.github/workflows/automated-release.yml

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ on:
8686
required: false
8787
type: boolean
8888
default: false
89+
create-cli-ticket:
90+
description: "Create CLI integration ticket"
91+
required: false
92+
type: boolean
93+
default: false
8994
sqs-integration:
9095
description: "Creat SQS integration ticket and PR"
9196
required: false
@@ -121,6 +126,11 @@ on:
121126
required: false
122127
type: boolean
123128
default: true
129+
require-rule-metadata-update:
130+
description: "Run rule metadata update check before release. Fails the release if metadata changes are detected and need to be merged first."
131+
required: false
132+
type: boolean
133+
default: false
124134
slack-channel:
125135
description: "Slack channel for notifications"
126136
required: false
@@ -263,15 +273,67 @@ jobs:
263273
[ "$CHECK_LICENSES" = "FAILED" ] && echo "- ❌ CheckLicenses" >> $GITHUB_STEP_SUMMARY
264274
fi
265275
276+
# This job runs the rule metadata update check to ensure metadata is up to date before release.
277+
# If changes are detected, a PR is created and the release is blocked until it is merged.
278+
update-rule-metadata:
279+
name: Update Rule Metadata
280+
if: |
281+
inputs.require-rule-metadata-update &&
282+
!cancelled() &&
283+
(needs.check-releasability.result == 'success' || needs.check-releasability.result == 'skipped')
284+
needs: [ check-releasability ]
285+
runs-on: ${{ inputs.runner-environment }}
286+
permissions:
287+
contents: write
288+
pull-requests: write
289+
id-token: write
290+
steps:
291+
- name: Update Rule Metadata
292+
id: update-rule-metadata
293+
uses: SonarSource/release-github-actions/update-rule-metadata@v1
294+
with:
295+
branch: ${{ inputs.branch }}
296+
297+
- name: Check Rule Metadata Changes
298+
if: steps.update-rule-metadata.outputs.has-changes == 'true'
299+
shell: bash
300+
env:
301+
PR_URL: ${{ steps.update-rule-metadata.outputs.pull-request-url }}
302+
run: |
303+
echo "::error::Rule metadata changes detected. The generated PR needs to be merged first before continuing with the release."
304+
echo "::error::Pull Request URL: $PR_URL"
305+
echo "::error::Please merge the PR and run this workflow again (start a new run instead of re-running failed jobs)."
306+
exit 1
307+
308+
- name: Summary
309+
if: ${{ inputs.verbose }}
310+
shell: bash
311+
env:
312+
BRANCH: ${{ inputs.branch }}
313+
HAS_CHANGES: ${{ steps.update-rule-metadata.outputs.has-changes }}
314+
PR_URL: ${{ steps.update-rule-metadata.outputs.pull-request-url || 'none' }}
315+
run: |
316+
echo "## 📋 Update Rule Metadata" >> $GITHUB_STEP_SUMMARY
317+
echo "" >> $GITHUB_STEP_SUMMARY
318+
echo "### What happened" >> $GITHUB_STEP_SUMMARY
319+
echo "- Ran rule metadata update check on branch \`$BRANCH\`." >> $GITHUB_STEP_SUMMARY
320+
echo "" >> $GITHUB_STEP_SUMMARY
321+
echo "### Results" >> $GITHUB_STEP_SUMMARY
322+
echo "- Changes detected: \`$HAS_CHANGES\`." >> $GITHUB_STEP_SUMMARY
323+
if [ "$HAS_CHANGES" = "true" ]; then
324+
echo "- Pull Request: $PR_URL" >> $GITHUB_STEP_SUMMARY
325+
fi
326+
266327
# This step determines the release version, Jira version name, and gathers release notes.
267328
# It sets up the necessary outputs for subsequent steps.
268329
# These outputs include the release version, Jira version name, release notes, Jira release notes, and Jira release URL.
269330
prepare-release:
270331
name: Prepare Release
271-
needs: [ check-releasability ]
332+
needs: [ check-releasability, update-rule-metadata ]
272333
if: |
273334
!cancelled() &&
274-
(needs.check-releasability.result == 'success' || needs.check-releasability.result == 'skipped')
335+
(needs.check-releasability.result == 'success' || needs.check-releasability.result == 'skipped') &&
336+
(needs.update-rule-metadata.result == 'success' || needs.update-rule-metadata.result == 'skipped')
275337
runs-on: ${{ inputs.runner-environment }}
276338
permissions:
277339
statuses: read
@@ -527,7 +589,7 @@ jobs:
527589
create-integration-tickets:
528590
name: Create Integration Tickets
529591
needs: [ prepare-release, publish-github-release, create-release-ticket ]
530-
if: ${{ inputs.create-slvs-ticket || inputs.create-slvscode-ticket || inputs.create-sle-ticket || inputs.create-sli-ticket || inputs.sqc-integration || inputs.sqs-integration }}
592+
if: ${{ inputs.create-slvs-ticket || inputs.create-slvscode-ticket || inputs.create-sle-ticket || inputs.create-sli-ticket || inputs.create-cli-ticket || inputs.sqc-integration || inputs.sqs-integration }}
531593
permissions:
532594
statuses: read
533595
contents: read
@@ -583,6 +645,17 @@ jobs:
583645
ticket-description: ${{ inputs.sq-ide-short-description != '' && inputs.sq-ide-short-description || inputs.short-description }}
584646
jira-release-url: ${{ needs.prepare-release.outputs.jira-release-url }}
585647

648+
- name: Create CLI Ticket
649+
if: ${{ inputs.create-cli-ticket }}
650+
uses: SonarSource/release-github-actions/create-integration-ticket@v1
651+
with:
652+
plugin-name: ${{ inputs.plugin-name }}
653+
release-version: ${{ needs.prepare-release.outputs.release-version }}
654+
release-ticket-key: ${{ needs.create-release-ticket.outputs.release-ticket-key }}
655+
target-jira-project: "CLI"
656+
ticket-description: ${{ inputs.sq-ide-short-description != '' && inputs.sq-ide-short-description || inputs.short-description }}
657+
jira-release-url: ${{ needs.prepare-release.outputs.jira-release-url }}
658+
586659
- name: Create SQC Ticket
587660
if: ${{ inputs.sqc-integration }}
588661
id: create-sqc-ticket
@@ -616,6 +689,7 @@ jobs:
616689
CREATE_SLVSCODE_TICKET: ${{ inputs.create-slvscode-ticket == true && 'true' || 'false' }}
617690
CREATE_SLE_TICKET: ${{ inputs.create-sle-ticket == true && 'true' || 'false' }}
618691
CREATE_SLI_TICKET: ${{ inputs.create-sli-ticket == true && 'true' || 'false' }}
692+
CREATE_CLI_TICKET: ${{ inputs.create-cli-ticket == true && 'true' || 'false' }}
619693
SQC_INTEGRATION: ${{ inputs.sqc-integration == true && 'true' || 'false' }}
620694
SQS_INTEGRATION: ${{ inputs.sqs-integration == true && 'true' || 'false' }}
621695
run: |
@@ -630,6 +704,7 @@ jobs:
630704
if [ "$CREATE_SLVSCODE_TICKET" = "true" ]; then echo "- SLVSCODE ticket created." >> $GITHUB_STEP_SUMMARY; fi
631705
if [ "$CREATE_SLE_TICKET" = "true" ]; then echo "- SLE ticket created." >> $GITHUB_STEP_SUMMARY; fi
632706
if [ "$CREATE_SLI_TICKET" = "true" ]; then echo "- SLI ticket created." >> $GITHUB_STEP_SUMMARY; fi
707+
if [ "$CREATE_CLI_TICKET" = "true" ]; then echo "- CLI ticket created." >> $GITHUB_STEP_SUMMARY; fi
633708
if [ "$SQC_INTEGRATION" = "true" ]; then echo "- SQC ticket \`${{ steps.create-sqc-ticket.outputs.ticket-key }}\` — ${{ steps.create-sqc-ticket.outputs.ticket-url }}" >> $GITHUB_STEP_SUMMARY; fi
634709
if [ "$SQS_INTEGRATION" = "true" ]; then echo "- SQS ticket \`${{ steps.create-sqs-ticket.outputs.ticket-key }}\` — ${{ steps.create-sqs-ticket.outputs.ticket-url }}" >> $GITHUB_STEP_SUMMARY; fi
635710
@@ -706,6 +781,7 @@ jobs:
706781
# to the RESULT_* env vars in the "Post Summary to Workflow" step.
707782
needs:
708783
- check-releasability
784+
- update-rule-metadata
709785
- prepare-release
710786
- publish-github-release
711787
- create-release-ticket
@@ -733,6 +809,7 @@ jobs:
733809
SQC_PR_URL: ${{ needs.update-analyzers.outputs.sqc-pull-request-url || 'not created' }}
734810
BUMP_VERSION_PR_URL: ${{ needs.bump-version.outputs.pull-request-url || 'not created' }}
735811
RESULT_CHECK_RELEASABILITY: ${{ needs.check-releasability.result }}
812+
RESULT_UPDATE_RULE_METADATA: ${{ needs.update-rule-metadata.result }}
736813
RESULT_PREPARE_RELEASE: ${{ needs.prepare-release.result }}
737814
RESULT_PUBLISH_GITHUB_RELEASE: ${{ needs.publish-github-release.result }}
738815
RESULT_CREATE_RELEASE_TICKET: ${{ needs.create-release-ticket.result }}
@@ -742,7 +819,7 @@ jobs:
742819
RESULT_UPDATE_ANALYZERS: ${{ needs.update-analyzers.result }}
743820
run: |
744821
ALL_SUCCESS=true
745-
for result in "$RESULT_CHECK_RELEASABILITY" "$RESULT_PREPARE_RELEASE" "$RESULT_PUBLISH_GITHUB_RELEASE" "$RESULT_CREATE_RELEASE_TICKET" "$RESULT_RELEASE_IN_JIRA" "$RESULT_CREATE_INTEGRATION_TICKETS" "$RESULT_UPDATE_ANALYZERS" "$RESULT_BUMP_VERSION"; do
822+
for result in "$RESULT_CHECK_RELEASABILITY" "$RESULT_UPDATE_RULE_METADATA" "$RESULT_PREPARE_RELEASE" "$RESULT_PUBLISH_GITHUB_RELEASE" "$RESULT_CREATE_RELEASE_TICKET" "$RESULT_RELEASE_IN_JIRA" "$RESULT_CREATE_INTEGRATION_TICKETS" "$RESULT_UPDATE_ANALYZERS" "$RESULT_BUMP_VERSION"; do
746823
if [[ "$result" != "success" && "$result" != "skipped" ]]; then
747824
ALL_SUCCESS=false
748825
break

0 commit comments

Comments
 (0)