Skip to content

Commit a972635

Browse files
GHA-155 Add branch freeze functionality to automated release workflow (#70)
1 parent 461ec61 commit a972635

2 files changed

Lines changed: 87 additions & 15 deletions

File tree

.github/workflows/automated-release.yml

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ on:
111111
required: false
112112
type: boolean
113113
default: false
114+
freeze-branch:
115+
description: "Freeze the branch during the release"
116+
required: false
117+
type: boolean
118+
default: true
119+
slack-channel:
120+
description: "Slack channel for notifications"
121+
required: false
122+
type: string
114123

115124
outputs:
116125
new-version:
@@ -121,12 +130,47 @@ env:
121130
USE_JIRA_SANDBOX: ${{ inputs.use-jira-sandbox == true && 'true' || 'false' }}
122131

123132
jobs:
124-
# Step 1: Prepare Release
133+
# This job freezes the specified branch to prevent changes during the release process.
134+
freeze-branch:
135+
name: Freeze ${{ inputs.branch }} branch
136+
if: ${{ inputs.freeze-branch }}
137+
runs-on: ${{ inputs.runner-environment }}
138+
permissions:
139+
id-token: write
140+
steps:
141+
- &freeze-branch-secrets
142+
id: secrets
143+
uses: SonarSource/vault-action-wrapper@v3
144+
with:
145+
secrets: |
146+
development/github/token/{REPO_OWNER_NAME_DASH}-lock token | lock_token;
147+
development/kv/data/slack token | slack_api_token;
148+
- &freeze-branch-toggle
149+
uses: sonarsource/gh-action-lt-backlog/ToggleLockBranch@v2
150+
with:
151+
github-token: ${{ fromJSON(steps.secrets.outputs.vault).lock_token }}
152+
slack-token: ${{ fromJSON(steps.secrets.outputs.vault).slack_api_token }}
153+
slack-channel: ${{ inputs.slack-channel }}
154+
branch-pattern: ${{ inputs.branch }}
155+
- name: Summary
156+
if: ${{ inputs.verbose }}
157+
shell: bash
158+
env:
159+
BRANCH: ${{ inputs.branch }}
160+
SLACK_CHANNEL: ${{ inputs.slack-channel || 'not set' }}
161+
run: |
162+
echo "## 🧊 Freeze Branch" >> $GITHUB_STEP_SUMMARY
163+
echo "" >> $GITHUB_STEP_SUMMARY
164+
echo "### What happened" >> $GITHUB_STEP_SUMMARY
165+
echo "- Locked branch pattern \`$BRANCH\` to prevent changes during the release." >> $GITHUB_STEP_SUMMARY
166+
echo "- Notifications sent to Slack channel: \`$SLACK_CHANNEL\`." >> $GITHUB_STEP_SUMMARY
167+
125168
# This step determines the release version, Jira version name, and gathers release notes.
126169
# It sets up the necessary outputs for subsequent steps.
127170
# These outputs include the release version, Jira version name, release notes, Jira release notes, and Jira release URL.
128171
prepare-release:
129172
name: Prepare Release
173+
needs: [ freeze-branch ]
130174
runs-on: ${{ inputs.runner-environment }}
131175
permissions:
132176
statuses: read
@@ -179,7 +223,6 @@ jobs:
179223
echo "- Release version: \`${{ steps.get-release-version.outputs.release-version }}\`." >> $GITHUB_STEP_SUMMARY
180224
echo "- Jira version name: \`${{ steps.get-jira-version.outputs.jira-version-name }}\`." >> $GITHUB_STEP_SUMMARY
181225
182-
# Step 2: Create Release Ticket
183226
# This step creates a Jira release ticket using the prepared release information.
184227
# It outputs the release ticket key and URL for further use.
185228
create-release-ticket:
@@ -222,7 +265,6 @@ jobs:
222265
echo "- Ticket key: \`${{ steps.create-ticket.outputs.release-ticket-key }}\`." >> $GITHUB_STEP_SUMMARY
223266
echo "- Ticket link: ${{ steps.create-ticket.outputs.release-ticket-url }}" >> $GITHUB_STEP_SUMMARY
224267
225-
# Step 3: Publish GitHub Release
226268
# This step publishes the GitHub release using the prepared release information and the created Jira release ticket.
227269
# It outputs the GitHub release URL for further use.
228270
publish-github-release:
@@ -261,7 +303,30 @@ jobs:
261303
echo "### Results" >> $GITHUB_STEP_SUMMARY
262304
echo "- Release page: ${{ steps.publish-github-release.outputs.release-url }}" >> $GITHUB_STEP_SUMMARY
263305
264-
# Step 4: Release in Jira
306+
# This job unfreezes the specified branch after the GitHub release is published.
307+
unfreeze-branch:
308+
name: Unfreeze ${{ inputs.branch }} branch
309+
if: ${{ inputs.freeze-branch }}
310+
runs-on: ${{ inputs.runner-environment }}
311+
needs: [ publish-github-release ]
312+
permissions:
313+
id-token: write
314+
steps:
315+
- *freeze-branch-secrets
316+
- *freeze-branch-toggle
317+
- name: Summary
318+
if: ${{ inputs.verbose }}
319+
shell: bash
320+
env:
321+
BRANCH: ${{ inputs.branch }}
322+
SLACK_CHANNEL: ${{ inputs.slack-channel || 'not set' }}
323+
run: |
324+
echo "## 🔓 Unfreeze Branch" >> $GITHUB_STEP_SUMMARY
325+
echo "" >> $GITHUB_STEP_SUMMARY
326+
echo "### What happened" >> $GITHUB_STEP_SUMMARY
327+
echo "- Unlocked branch pattern \`$BRANCH\` after publishing the GitHub release." >> $GITHUB_STEP_SUMMARY
328+
echo "- Notifications sent to Slack channel: \`$SLACK_CHANNEL\`." >> $GITHUB_STEP_SUMMARY
329+
265330
# This step releases the version in Jira and moves the release ticket to the "Technical Release Done" status.
266331
# It outputs the new version name and integration ticket keys and URLs.
267332
release-in-jira:
@@ -309,7 +374,6 @@ jobs:
309374
echo "### Results" >> $GITHUB_STEP_SUMMARY
310375
echo "- New Jira version: \`${{ steps.create-jira-version.outputs.jira-new-version-name }}\`." >> $GITHUB_STEP_SUMMARY
311376
312-
# Step 5: Create Integration Tickets
313377
# This step creates integration tickets in various Jira projects based on the inputs provided.
314378
# It creates tickets for SLVS, SLVSCODE, SLE, SLI, SQC, and SQS as specified.
315379
# It outputs the integration ticket keys for SQC and SQS for further use.
@@ -422,7 +486,6 @@ jobs:
422486
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
423487
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
424488
425-
# Step 6: Update Analyzers in SQS and SQC
426489
# This step updates the analyzers in SQS and SQC by creating pull requests based on the integration tickets created in the previous step.
427490
# It outputs the pull request URLs for SQS and SQC for further use.
428491
update-analyzers:
@@ -485,7 +548,6 @@ jobs:
485548
if [ "$SQS_INTEGRATION" = "true" ]; then echo "- SQS PR: ${{ steps.update-sqs.outputs.pull-request-url }}" >> $GITHUB_STEP_SUMMARY; fi
486549
if [ "$SQC_INTEGRATION" = "true" ]; then echo "- SQC PR: ${{ steps.update-sqc.outputs.pull-request-url }}" >> $GITHUB_STEP_SUMMARY; fi
487550
488-
# Step 7: Summarize Release
489551
# This step summarizes the results of the entire release process.
490552
# It checks the outcomes of all previous steps and generates a summary indicating whether the release was
491553
# successful or failed, along with relevant links and information.

docs/AUTOMATED_RELEASE.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ This reusable GitHub Actions workflow automates the end-to-end release process a
66

77
The workflow orchestrates these steps:
88

9-
1. Determine the release version and Jira version name
10-
2. Optionally generate Jira release notes if not provided
11-
3. Create a Jira release ticket
12-
4. Publish a GitHub release (draft or final)
13-
5. Release the current Jira version and create the next version in Jira
14-
6. Optionally create integration tickets (SLVS, SLVSCODE, SLE, SLI, SQC, SQS)
15-
7. Optionally open analyzer update PRs in SQS and SQC
16-
8. Optionally post per-job and final workflow summaries when `verbose` is enabled
9+
1. Optionally freeze (lock) the target branch at the start of the release
10+
2. Determine the release version and Jira version name
11+
3. Optionally generate Jira release notes if not provided
12+
4. Create a Jira release ticket
13+
5. Publish a GitHub release (draft or final)
14+
6. Release the current Jira version and create the next version in Jira
15+
7. Optionally create integration tickets (SLVS, SLVSCODE, SLE, SLI, SQC, SQS)
16+
8. Optionally open analyzer update PRs in SQS and SQC
17+
9. Optionally post per-job and final workflow summaries when `verbose` is enabled
1718

1819
## Dependencies
1920

@@ -28,6 +29,7 @@ This workflow composes several actions from this repository:
2829
- `SonarSource/release-github-actions/create-integration-ticket`
2930
- `SonarSource/release-github-actions/update-analyzer`
3031
- `SonarSource/release-github-actions/update-release-ticket-status`
32+
- Branch lock/unlock via `sonarsource/gh-action-lt-backlog/ToggleLockBranch`
3133

3234
## Inputs
3335

@@ -57,6 +59,8 @@ This workflow composes several actions from this repository:
5759
| `runner-environment` | Runner labels/environment | No | `sonar-m` |
5860
| `release-process` | Release process documentation URL | No | General page |
5961
| `verbose` | When `true`, posts per-job summaries and a final run summary | No | `false` |
62+
| `freeze-branch` | When `true`, locks the target branch during the release and unlocks it after publishing | No | `true` |
63+
| `slack-channel` | Slack channel to notify when locking/unlocking the branch | No | - |
6064

6165
## Outputs
6266

@@ -112,11 +116,17 @@ jobs:
112116
sqs-integration: true
113117
sqc-integration: true
114118
release-automation-secret-name: "sonar-csd-release-automation"
119+
slack-channel: "release-notifications"
115120
verbose: ${{ inputs.verbose }}
116121
```
117122
118123
## Notes
119124
125+
- When `freeze-branch: true`, the workflow will:
126+
- Lock the specified branch at the start of the release
127+
- Proceed with the release steps
128+
- Unlock the branch after the GitHub release is published
129+
- Send lock/unlock notifications to the configured `slack-channel` if provided
120130
- When `release-notes` is empty, Jira release notes are fetched and used.
121131
- Integration tickets and analyzer update PRs are created only if their respective flags are enabled and prerequisites are met (e.g., secret name for PR creation).
122132
- Summaries:

0 commit comments

Comments
 (0)