Skip to content

Commit 1ca8090

Browse files
committed
auto tag jira
1 parent 3166a79 commit 1ca8090

4 files changed

Lines changed: 124 additions & 1 deletion

File tree

.github/workflows/tag-release-devcontainer.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ on:
2929
required: false
3030
type: string
3131
default: "main"
32+
update_jira:
33+
description: "Whether to update Jira issues during semantic-release"
34+
required: false
35+
type: boolean
36+
default: false
37+
jira_release_prefix:
38+
description: "Release prefix sent to Jira release tagging"
39+
required: false
40+
type: string
41+
default: ""
3242
extra_artifact_name:
3343
description: "An extra artifact to include in the release"
3444
required: false
@@ -58,6 +68,9 @@ on:
5868
NPM_TOKEN:
5969
required: false
6070
description: "NPM token to publish packages"
71+
EXECUTE_JIRA_LAMBDA_ROLE:
72+
required: false
73+
description: "ARN of the role to assume when executing the Jira update lambda"
6174
jobs:
6275
tag_release:
6376
runs-on: ubuntu-22.04
@@ -75,6 +88,16 @@ jobs:
7588
- name: copy .tool-versions
7689
run: |
7790
cp /home/vscode/.tool-versions "$HOME/.tool-versions"
91+
92+
- name: connect to dev account to run release notes lambda
93+
uses: aws-actions/configure-aws-credentials@00943011d9042930efac3dcd3a170e4273319bc8
94+
if: ${{ inputs.update_jira == 'true' }}
95+
with:
96+
aws-region: eu-west-2
97+
role-to-assume: ${{ secrets.EXECUTE_JIRA_LAMBDA_ROLE }}
98+
role-session-name: execute-jira-lambda-session
99+
unset-current-credentials: true
100+
78101
- name: Clone calling repo
79102
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
80103
with:
@@ -86,6 +109,7 @@ jobs:
86109
with:
87110
repository: NHSDigital/eps-common-workflows
88111
sparse-checkout-cone-mode: false
112+
ref: update_jira
89113
path: common_workflow_config
90114
sparse-checkout: |
91115
package.json
@@ -191,6 +215,8 @@ jobs:
191215
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
192216
MAIN_BRANCH: ${{ inputs.main_branch }}
193217
EXTRA_ASSET: ${{ inputs.extra_artifact_name }}
218+
UPDATE_JIRA: ${{ inputs.update_jira }}
219+
JIRA_RELEASE_PREFIX: ${{ inputs.jira_release_prefix }}
194220

195221
- name: Create semantic release tag
196222
if: ${{ !inputs.dry_run }}
@@ -201,6 +227,8 @@ jobs:
201227
TAG_FORMAT: ${{ inputs.tag_format }}
202228
MAIN_BRANCH: ${{ inputs.main_branch }}
203229
EXTRA_ASSET: ${{ inputs.extra_artifact_name }}
230+
UPDATE_JIRA: ${{ inputs.update_jira }}
231+
JIRA_RELEASE_PREFIX: ${{ inputs.jira_release_prefix }}
204232
run: |
205233
npx semantic-release --tag-format "${TAG_FORMAT}"
206234

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
},
1313
"author": "NHS Digital",
1414
"license": "MIT",
15+
"dependencies": {
16+
"@aws-sdk/client-cloudformation": "^3.877.0",
17+
"@aws-sdk/client-lambda": "^3.877.0"
18+
},
1519
"devDependencies": {
1620
"@semantic-release/changelog": "^6.0.3",
1721
"@semantic-release/commit-analyzer": "^13.0.1",
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const {
2+
CloudFormationClient,
3+
ListExportsCommand
4+
} = require("@aws-sdk/client-cloudformation")
5+
const { LambdaClient, InvokeCommand } = require("@aws-sdk/client-lambda")
6+
7+
async function createAndTagJiraIssues(version, releasePrefix, jiraTickets) {
8+
try {
9+
const exportName = "release-notes:ReleaseCutLambdaName"
10+
const cloudFormationClient = new CloudFormationClient({})
11+
const lambdaClient = new LambdaClient({})
12+
13+
let functionName
14+
let nextToken
15+
16+
do {
17+
const exportsResponse = await cloudFormationClient.send(
18+
new ListExportsCommand({ NextToken: nextToken })
19+
)
20+
21+
functionName = exportsResponse.Exports?.find(
22+
exportItem => exportItem.Name === exportName
23+
)?.Value
24+
25+
nextToken = exportsResponse.NextToken
26+
} while (!functionName && nextToken)
27+
28+
if (!functionName) {
29+
throw new Error(`Could not resolve CloudFormation export '${exportName}'`)
30+
}
31+
32+
const payload = {
33+
releaseTag: version,
34+
releasePrefix,
35+
tickets: jiraTickets
36+
}
37+
38+
await lambdaClient.send(
39+
new InvokeCommand({
40+
FunctionName: functionName,
41+
Payload: Buffer.from(JSON.stringify(payload))
42+
})
43+
)
44+
} catch (error) {
45+
console.error("Failed to create and tag Jira issues:", error)
46+
}
47+
48+
return { success: true }
49+
}
50+
51+
module.exports = {
52+
createAndTagJiraIssues,
53+
async success(pluginConfig, context) {
54+
const { nextRelease, commits } = context
55+
56+
const version = nextRelease.version
57+
58+
// Extract Jira tickets from commit messages
59+
const jiraTickets = new Set()
60+
61+
const jiraRegex = /([A-Z]+-\d+)/g
62+
63+
for (const commit of commits) {
64+
const matches = commit.message.match(jiraRegex)
65+
if (matches) {
66+
matches.forEach(t => jiraTickets.add(t))
67+
}
68+
}
69+
70+
const releasePrefix = pluginConfig?.releasePrefix
71+
if (!releasePrefix) {
72+
console.warn("JIRA_RELEASE_PREFIX is not set; invoking release-notes lambda with undefined releasePrefix.")
73+
}
74+
await createAndTagJiraIssues(version, releasePrefix, [...jiraTickets])
75+
}
76+
}

release.config.cjs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ const mainBranch = process.env.MAIN_BRANCH || "main"
77

88
const pypiPublish = process.env.PYPI_PUBLISH?.toLowerCase() === 'true' || false
99
const pypiToken = process.env.PYPI_TOKEN
10+
const updateJira = process.env.UPDATE_JIRA?.toLowerCase() === "true"
11+
const jiraReleasePrefix = process.env.JIRA_RELEASE_PREFIX
12+
13+
if (updateJira && !jiraReleasePrefix) {
14+
// eslint-disable-next-line no-console
15+
console.warn("UPDATE_JIRA is true but JIRA_RELEASE_PREFIX is not set; releasePrefix will be undefined.")
16+
}
1017

1118
module.exports = {
1219
branches: [
@@ -103,6 +110,14 @@ module.exports = {
103110
failComment: false,
104111
failTitle: false
105112
}
106-
]
113+
],
114+
...(updateJira ? [
115+
[
116+
"./packages/semantic_release_jira",
117+
{
118+
releasePrefix: jiraReleasePrefix
119+
}
120+
]
121+
] : [])
107122
]
108123
}

0 commit comments

Comments
 (0)