Skip to content

Commit b4a4a80

Browse files
SONARIAC-2094 Add "Publish New Release" Github Action (#7)
* add 'Publish Github Release' action * add jira_release_name to create-jira-release-ticket action * use correct env var for gh cli token * fix input typo * update gh cli step * checkout repo as first step * add readme * fix formatting of python script * use release SHA hash for checkout action * use correct references to the github actions in the examples * add check for release workflow * drop draft check from new step for testing * hardcode version check for testing * hardcode failing release for testing * test the failing run pt2 * update README * update description in README * update repo readme
1 parent efbbe69 commit b4a4a80

File tree

10 files changed

+457
-32
lines changed

10 files changed

+457
-32
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ A centralized collection of reusable GitHub Actions designed to streamline and a
55
## Available Actions
66

77
* [**Create Jira Release Ticket**](create-jira-release-ticket/README.md): Automates the creation of an "Ask for release" ticket in Jira.
8-
* [**Check Releasability Status**](check-releasability-status/README.md): Checks the releasability status of the master branch and extracts the version if successful.
8+
* [**Check Releasability Status**](check-releasability-status/README.md): Checks the releasability status and extracts the version if successful.
99
* [**Update Release ticket Status**](update-release-ticket-status/README.md): Updates the status of a Jira release ticket and can change its assignee.
10+
* [**Publish GitHub Release**](publish-github-release/README.md): Publishes a GitHub Release with notes fetched from Jira or provided directly.
1011
* [**Release Jira Version**](release-jira-version/README.md): Releases a Jira version and creates the next one.

create-jira-release-ticket/README.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,35 @@ This GitHub Action automates the creation of an "Ask for release" ticket in Jira
55
The action is self-contained and uses a Python script to interact with the Jira API.
66
## Prerequisites
77

8-
The action requires that the repository needs to have the `development/kv/data/jira` token configured in vault.
8+
The action requires that the repository has the `development/kv/data/jira` token configured in vault.
99
This can be done using the SPEED self-service portal ([more info](https://xtranet-sonarsource.atlassian.net/wiki/spaces/Platform/pages/3553787989/Manage+Vault+Policy+-+SPEED)).
1010

1111
## Inputs
1212

1313
The following inputs can be configured for the action:
1414

15-
| Input | Description | Required | Default |
16-
|------------------------|--------------------------------------------------------------------------------------------------------------------|----------|---------|
17-
| `jira_user` | The Jira user (email) for authentication. | `true` | |
18-
| `jira_token` | The Jira API token for authentication. | `true` | |
19-
| `project_key` | The project key (e.g., `SONARIAC`). | `true` | |
20-
| `project_name` | The display name of the project (e.g., `SonarIaC`). Will be used as the prefix of the resulting release ticket. | `true` | |
21-
| `version` | The new version string being released (e.g., `1.2.3`). | `true` | |
22-
| `short_description` | A brief description of the release. | `true` | |
23-
| `sq_compatibility` | The SonarQube compatibility version (e.g., `2025.3`). | `true` | |
24-
| `targeted_product` | The targeted product version (e.g., `11.0`). | `false` | |
25-
| `use_sandbox` | Set to `false` to use the Jira production server. | `false` | `true` |
26-
| `documentation_status` | The status of the release documentation. | `false` | `N/A` |
27-
| `rule_props_changed` | Whether rule properties have changed (`Yes` or `No`). | `false` | `No` |
28-
| `jira_release_name` | The specific Jira release version to use. If omitted and there is only one unreleased version it will released it. | `false` | `''` |
29-
| `sonarlint_changelog` | The SonarLint changelog content. | `false` | `''` |
15+
| Input | Description | Required | Default |
16+
|------------------------|-------------------------------------------------------------------------------------------------------------------|----------|---------|
17+
| `jira_user` | The Jira user (email) for authentication. | `true` | |
18+
| `jira_token` | The Jira API token for authentication. | `true` | |
19+
| `project_key` | The project key (e.g., `SONARIAC`). | `true` | |
20+
| `project_name` | The display name of the project (e.g., `SonarIaC`). Will be used as the prefix of the resulting release ticket. | `true` | |
21+
| `version` | The new version string being released (e.g., `1.2.3`). | `true` | |
22+
| `short_description` | A brief description of the release. | `true` | |
23+
| `sq_compatibility` | The SonarQube compatibility version (e.g., `2025.3`). | `true` | |
24+
| `targeted_product` | The targeted product version (e.g., `11.0`). | `false` | |
25+
| `use_sandbox` | Set to `false` to use the Jira production server. | `false` | `true` |
26+
| `documentation_status` | The status of the release documentation. | `false` | `N/A` |
27+
| `rule_props_changed` | Whether rule properties have changed (`Yes` or `No`). | `false` | `No` |
28+
| `jira_release_name` | The specific Jira release version to use. If omitted and there is only one unreleased version it will release it. | `false` | `''` |
29+
| `sonarlint_changelog` | The SonarLint changelog content. | `false` | `''` |
3030

3131
## Outputs
3232

33-
| Output | Description |
34-
|--------------|------------------------------------------------|
35-
| `ticket_key` | The key of the jira ticket (e.g., `REL-1234`). |
33+
| Output | Description |
34+
|---------------------|--------------------------------------------------|
35+
| `ticket_key` | The key of the Jira ticket (e.g., `REL-1234`). |
36+
| `jira_release_name` | The name of the Jira release used by the action. |
3637

3738
## Example Usage
3839

@@ -87,7 +88,7 @@ jobs:
8788
8889
- name: Create Jira Release Ticket
8990
id: create_ticket
90-
uses: SonarSource/release-github-actions/.github/actions/create-jira-release-ticket
91+
uses: SonarSource/release-github-actions/.github/actions/create-jira-release-ticket@master
9192
with:
9293
jira_user: ${{ fromJSON(steps.secrets.outputs.vault).JIRA_USER }}
9394
jira_token: ${{ fromJSON(steps.secrets.outputs.vault).JIRA_TOKEN }}
@@ -100,5 +101,7 @@ jobs:
100101
jira_release_name: ${{ github.event.inputs.jira_release }}
101102
sonarlint_changelog: ${{ github.event.inputs.sonarlint_changelog }}
102103

103-
- name: Echo Ticket Key
104-
run: echo "The created Jira ticket key is ${{ steps.create_ticket.outputs.ticket_key }}"
104+
- name: Echo Ticket Key and Release Name
105+
run: |
106+
echo "The created Jira ticket key is ${{ steps.create_ticket.outputs.ticket_key }}"
107+
echo "The Jira release name used is ${{ steps.create_ticket.outputs.jira_release_name }}"

create-jira-release-ticket/action.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ outputs:
5252
ticket_key:
5353
description: 'The key of the created Jira ticket (e.g., REL-123)'
5454
value: ${{ steps.run_python_script.outputs.ticket_key }}
55+
jira_release_name:
56+
description: 'The name of the Jira release found or used by the script.'
57+
value: ${{ steps.run_python_script.outputs.jira_release_name }}
5558

5659
runs:
5760
using: "composite"
@@ -74,7 +77,7 @@ runs:
7477
SANDBOX_FLAG="--use-sandbox"
7578
fi
7679
77-
TICKET_KEY=$(python ${{ github.action_path }}/create_release_ticket.py \
80+
python ${{ github.action_path }}/create_release_ticket.py \
7881
--project-key="${{ inputs.project_key }}" \
7982
--project-name="${{ inputs.project_name }}" \
8083
--version="${{ inputs.version }}" \
@@ -85,9 +88,7 @@ runs:
8588
--documentation-status="${{ inputs.documentation_status }}" \
8689
--rule-props-changed="${{ inputs.rule_props_changed }}" \
8790
--jira-release-name="${{ inputs.jira_release_name }}" \
88-
--sonarlint-changelog="${{ inputs.sonarlint_changelog }}"
89-
)
90-
echo "ticket_key=${TICKET_KEY}" >> $GITHUB_OUTPUT
91+
--sonarlint-changelog="${{ inputs.sonarlint_changelog }}" >> $GITHUB_OUTPUT
9192
env:
9293
JIRA_USER: ${{ inputs.jira_user }}
9394
JIRA_TOKEN: ${{ inputs.jira_token }}

create-jira-release-ticket/create_release_ticket.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def eprint(*args, **kwargs):
3838
print(*args, file=sys.stderr, **kwargs)
3939

4040

41+
# noinspection DuplicatedCode
4142
def get_jira_instance(use_sandbox=False):
4243
"""
4344
Initializes and returns a JIRA client instance and the server URL used.
@@ -191,7 +192,8 @@ def main():
191192
parser.add_argument("--short-description", required=True, help="A short description for the release.")
192193
parser.add_argument("--sq-compatibility", required=True, help="SonarQube compatibility version (e.g., 2025.3).")
193194
parser.add_argument("--targeted-product", help="The targeted product version (e.g., 11.0).")
194-
parser.add_argument('--use-sandbox', action='store_true', help="Use the sandbox server instead of the production Jira.")
195+
parser.add_argument('--use-sandbox', action='store_true',
196+
help="Use the sandbox server instead of the production Jira.")
195197
parser.add_argument("--documentation-status", default="N/A", help="Status of the documentation.")
196198
parser.add_argument("--rule-props-changed", default="No", choices=['Yes', 'No'],
197199
help="Whether rule properties have changed.")
@@ -208,10 +210,12 @@ def main():
208210
eprint("\n" + "=" * 50)
209211
eprint("🎉 Successfully created release ticket!")
210212
eprint(f" Ticket Key: {ticket.key}")
213+
eprint(f" Release Name: {release_notes_info.name}")
211214
eprint(f" Ticket URL: {ticket.permalink()}")
212215
eprint("=" * 50)
213216

214-
print(ticket.key)
217+
print(f"ticket_key={ticket.key}")
218+
print(f"jira_release_name={release_notes_info.name}")
215219

216220

217221
if __name__ == "__main__":

publish-github-release/README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Publish GitHub Release Action
2+
3+
This GitHub Action automates the creation of a GitHub Release. It can generate release notes by fetching the details directly from a Jira release version, or it can use release notes provided directly as an input.
4+
If not publishing a draft release, the action will wait for the release workflow to complete before reporting its status.
5+
6+
This action uses the GitHub CLI to create the release and a Python script to interact with the Jira API.
7+
8+
## Prerequisites
9+
10+
To fetch release notes from Jira, the action requires that the repository has the `development/kv/data/jira` token configured in vault.
11+
This can be done using the SPEED self-service portal ([more info](https://xtranet-sonarsource.atlassian.net/wiki/spaces/Platform/pages/3553787989/Manage+Vault+Policy+-+SPEED)).
12+
13+
The action also requires a `github_token` with `contents: write` permissions to create the release. The default `${{ github.token }}` is usually sufficient.
14+
15+
## Inputs
16+
17+
The following inputs can be configured for the action:
18+
19+
| Input | Description | Required | Default |
20+
|--------------------------|------------------------------------------------------------------------------------------------------------------|----------|-----------------------|
21+
| `github_token` | The GitHub token for API calls. | `true` | `${{ github.token }}` |
22+
| `version` | The version number for the new release (e.g., `v1.0.0`). This will also be the tag name. | `true` | |
23+
| `branch` | The branch, commit, or tag to create the release from. | `false` | `master` |
24+
| `draft` | A boolean value to indicate if the release should be a draft. | `false` | `true` |
25+
| `release_notes` | The full markdown content for the release notes. If provided, this is used directly, ignoring Jira inputs. | `false` | `''` |
26+
| `jira_release_name` | The name of the Jira release version. If provided and `release_notes` is empty, notes will be fetched from Jira. | `false` | `''` |
27+
| `jira_project_key` | The Jira project key (e.g., "SONARPHP") to fetch notes from. Required if using `jira_release_name`. | `false` | |
28+
| `jira_user` | Jira user (email) for authentication. Required if using `jira_release_name`. | `false` | |
29+
| `jira_token` | Jira API token for authentication. Required if using `jira_release_name`. | `false` | |
30+
| `issue_types` | Optional comma-separated list of Jira issue types to include in the release notes, in order of appearance. | `false` | `''` |
31+
| `use_sandbox` | Set to `false` to use the Jira production server instead of the sandbox. | `false` | `true` |
32+
| `wait_for_workflow_name` | The name or file name of the workflow to wait for upon a non-draft release. If empty, this step is skipped. | `false` | `sonar-release` |
33+
34+
## Outputs
35+
36+
| Output | Description |
37+
|---------------|---------------------------------------|
38+
| `release_url` | The URL of the newly created release. |
39+
40+
## Example Usage
41+
42+
Here is an example of how to use this action in a workflow. This job can be triggered manually to publish a new release, with release notes generated from a specified Jira version.
43+
44+
```yaml
45+
name: Publish New Release
46+
47+
on:
48+
workflow_dispatch:
49+
inputs:
50+
version:
51+
description: 'The version to release (e.g., v1.2.3)'
52+
required: true
53+
jira_release_name:
54+
description: 'The corresponding release name in Jira'
55+
required: true
56+
57+
jobs:
58+
publish_release:
59+
name: Publish GitHub Release
60+
runs-on: ubuntu-latest
61+
permissions:
62+
contents: write # Required to create a release
63+
id-token: write # For Vault integration
64+
65+
steps:
66+
- name: Checkout code
67+
uses: actions/checkout@v4
68+
69+
- name: Get Jira Credentials from Vault
70+
id: secrets
71+
uses: SonarSource/vault-action-wrapper@v3
72+
with:
73+
secrets: |
74+
development/kv/data/jira user | JIRA_USER;
75+
development/kv/data/jira token | JIRA_TOKEN;
76+
77+
- name: Publish GitHub Release
78+
id: publish
79+
uses: SonarSource/release-github-actions/update-release-ticket-status@master
80+
with:
81+
version: ${{ github.event.inputs.version }}
82+
jira_project_key: 'YOUR_PROJ_KEY'
83+
jira_release_name: ${{ github.event.inputs.jira_release_name }}
84+
jira_user: ${{ fromJSON(steps.secrets.outputs.vault).JIRA_USER }}
85+
jira_token: ${{ fromJSON(steps.secrets.outputs.vault).JIRA_TOKEN }}
86+
draft: false
87+
use_sandbox: false
88+
89+
- name: Print Release URL
90+
run: echo "Successfully published release at ${{ steps.publish.outputs.release_url }}"

0 commit comments

Comments
 (0)