Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIJN-6651 - release notificaties #985

Merged
merged 69 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
7b010b0
git commands for release page
janthijs Sep 12, 2023
cc2113f
fix: add workflow for pr title check
janthijs Sep 12, 2023
5b39e5f
fix: ctd script
janthijs Sep 12, 2023
1b559af
fix: update jenkisn file
janthijs Oct 3, 2023
83fdd41
fix: move order
janthijs Oct 3, 2023
41cd367
update jenkins file
janthijs Oct 3, 2023
7c8e616
jenkins
janthijs Oct 3, 2023
79524cb
disable when
janthijs Oct 3, 2023
7004836
disable
janthijs Oct 3, 2023
b6cef51
add space
janthijs Oct 3, 2023
26cb5ff
update docker file
janthijs Oct 3, 2023
6ed87a9
pass vars
janthijs Oct 3, 2023
def7337
send to js
janthijs Oct 3, 2023
349b8c6
use run
janthijs Oct 3, 2023
2e0a92b
try this
janthijs Oct 3, 2023
dca7dd1
try this
janthijs Oct 3, 2023
2cdc01b
try this
janthijs Oct 3, 2023
9431426
stringify
janthijs Oct 3, 2023
90f03fa
include https
janthijs Oct 3, 2023
ff11555
fix: move vars
janthijs Oct 3, 2023
4aafb8e
fix: combine it all
janthijs Oct 3, 2023
719b5e7
fix: rename script
janthijs Oct 3, 2023
958095b
try this
janthijs Oct 6, 2023
d2403d2
update sh
janthijs Oct 6, 2023
b3e216d
escape char
janthijs Oct 6, 2023
4371ea6
fix
janthijs Oct 6, 2023
b0e1c7c
fix: update
janthijs Oct 6, 2023
05dc1ac
fix: escape
janthijs Oct 6, 2023
0c9ce4b
add script
janthijs Oct 6, 2023
42553b7
try this
janthijs Oct 6, 2023
2c78b9a
fix
janthijs Oct 6, 2023
f6ff08f
fix
janthijs Oct 6, 2023
6307e46
echo
janthijs Oct 6, 2023
2c00229
try this
janthijs Oct 9, 2023
5e8dff9
fix: run script
janthijs Oct 9, 2023
f432e87
fix: update pipeline
janthijs Oct 9, 2023
d04bdfb
log some more
janthijs Oct 9, 2023
6a37318
fix: use workflow
janthijs Nov 10, 2023
8965fea
Build(deps): bump @sentry/node from 7.77.0 to 7.80.0 (#1049)
dependabot[bot] Nov 14, 2023
8b73479
Build(deps): bump @types/uid-safe from 2.1.4 to 2.1.5 (#1048)
dependabot[bot] Nov 14, 2023
e396331
Build(deps): bump @types/proj4 from 2.5.4 to 2.5.5 (#1047)
dependabot[bot] Nov 14, 2023
3e48588
Build(deps): bump @types/morgan from 1.9.8 to 1.9.9 (#1046)
dependabot[bot] Nov 14, 2023
99e9d75
Build(deps): bump @types/throttle-debounce from 5.0.1 to 5.0.2 (#1045)
dependabot[bot] Nov 14, 2023
87a5723
MIJN-7157 Actueel teksten aangepast en nog wat wijzigingen (#1044)
YacineHallo Nov 14, 2023
867df02
fix: move to github script
janthijs Nov 14, 2023
fb4e44e
fix: update scripts version
janthijs Nov 14, 2023
7686c3e
temp update
janthijs Nov 14, 2023
697c988
Merge branch 'main' into MIJN-6651-release
janthijs Nov 14, 2023
131e288
fix: relax check
janthijs Nov 14, 2023
8dbf6d0
remove if
janthijs Nov 14, 2023
45c939d
fix: add checkout
janthijs Nov 14, 2023
6110a44
fix: just use node
janthijs Nov 14, 2023
1f6ec8c
fix: add more commits
janthijs Nov 14, 2023
40e95de
fix: update
janthijs Nov 14, 2023
56cb256
fix: more agressive fetching
janthijs Nov 14, 2023
3261b2a
fix: update
janthijs Nov 14, 2023
a5ee79d
fix
janthijs Nov 14, 2023
c31882b
fix: test
janthijs Nov 14, 2023
247d284
remove if
janthijs Nov 14, 2023
d0ec070
fix: clean up
janthijs Nov 14, 2023
ee6b52d
Merge branch 'main' into MIJN-6651-release
janthijs Nov 14, 2023
55f291e
fix: clean up jenkins file
janthijs Nov 14, 2023
00df825
fix: clean up code
janthijs Nov 14, 2023
e1fdf8f
Merge branch 'MIJN-6651-release' of https://github.com/Amsterdam/mijn…
janthijs Nov 14, 2023
59b9976
Merge branch 'main' into MIJN-6651-release
timvanoostrom Nov 19, 2023
9a4907f
Merge branch 'main' into MIJN-6651-release
janthijs Nov 21, 2023
75f5e55
Merge branch 'main' into MIJN-6651-release
janthijs Nov 21, 2023
46b6154
Merge branch 'main' into MIJN-6651-release
janthijs Nov 21, 2023
aaefe80
Merge branch 'main' into MIJN-6651-release
janthijs Nov 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/pr-title-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Taken from: https://levelup.gitconnected.com/enforcing-jira-ticket-formatting-in-github-pr-titles-and-commit-messages-78d9755568df
name: 'PR Title Check'
on:
pull_request:
types: [opened, edited, synchronize]
jobs:
check-title:
runs-on: ubuntu-latest
steps:
- name: Check PR title
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const payload = context.payload
const prTitle = payload.pull_request.title

// Titel moet beginnen met mijn-xxxx of Bump!
const jiraPattern = /(mijn-\d+|bump!)/gi
if (!jiraPattern.test(prTitle)) {
console.log('The PR title does not match JIRA ticket format!')
// Fails the workflow
core.setFailed('PR title does not match JIRA ticket format!')
} else {
console.log('PR title format is correct.')
}
17 changes: 17 additions & 0 deletions .github/workflows/release-notification.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 'Release notification'
on: create
jobs:
create-notification:
if: ${{ contains(github.ref, 'release-v') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Create release notification
env:
webhook_host: ${{ secrets.MS_TEAMS_WEBHOOK_HOST }}
webhook_path: ${{ secrets.MS_TEAMS_RELEASE_NOTIFICATION_WEBHOOK_PATH }}
run: npm run release:notification
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"bff-api:test": "cross-env MA_APP_MODE=unittest vitest --environment=node src/server src/universal",
"bff-api:serve-build": "node build-bff/server/app",
"bff-api:serve-dev": "ts-node --project ./tsconfig.bff.json ./src/bffserver.ts",
"bff-api:build": "tsc --project ./tsconfig.bff.json"
"bff-api:build": "tsc --project ./tsconfig.bff.json",
"release:notification": "node scripts/release-notifications/release-notes"
},
"browserslist": [
">0.2%",
Expand Down
113 changes: 113 additions & 0 deletions scripts/release-notifications/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
function getReleaseCardJson(changes) {
const now = new Date();

const rows = changes.map((change) => ({
type: 'TableRow',
cells: [
{
type: 'TableCell',
items: [
{
type: 'TextBlock',
text: `[${change.ticket}](https://gemeente-amsterdam.atlassian.net/browse/${change.ticket})`,
wrap: true,
},
],
},
{
type: 'TableCell',
items: [
{
type: 'TextBlock',
text: change.description,
wrap: true,
},
],
},
{
type: 'TableCell',
items: [
{
type: 'TextBlock',
text: change.date,
wrap: true,
},
],
},
],
}));

return {
type: 'AdaptiveCard',
$schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
version: '1.5',
body: [
{
type: 'TextBlock',
text: `Release overzicht van ${now.getDate()}-${
now.getMonth() + 1
}-${now.getFullYear()}`,
wrap: true,
style: 'heading',
},
{
type: 'Table',
columns: [
{
width: 1,
},
{
width: 2,
},
{
width: 3,
},
],
rows: [
{
type: 'TableRow',
cells: [
{
type: 'TableCell',
items: [
{
type: 'TextBlock',
text: 'Ticket',
wrap: true,
},
],
style: 'accent',
},
{
type: 'TableCell',
items: [
{
type: 'TextBlock',
text: 'Omschrijving',
wrap: true,
},
],
style: 'accent',
},
{
type: 'TableCell',
items: [
{
type: 'TextBlock',
text: 'Dagen in main',
wrap: true,
},
],
style: 'accent',
},
],
},
...rows,
],
firstRowAsHeader: true,
},
],
};
}

module.exports = { getReleaseCardJson };
80 changes: 80 additions & 0 deletions scripts/release-notifications/release-notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const child_process = require('child_process');
const { getReleaseCardJson } = require('./card');
const { sendTeamsMessage } = require('./teams');

const RELEASE_MERGE_MESSAGE = 'Bump!';

// Small wrapper
function executeCommandSync(command) {
return child_process.execSync(command).toString();
}

function getDateDiff(date1, date2 = new Date()) {
if (
date1.getDate() === date2.getDate() &&
date1.getMonth() === date2.getMonth() &&
date1.getFullYear() === date2.getFullYear()
) {
return `Sinds vandaag in main`;
}

//Set hours, minutes and seconds to zero
date1.setHours(0, 0, 0, 0);
date2.setHours(0, 0, 0, 0);

const t2 = date2.getTime(); //Get time in milliseconds.
const t1 = date1.getTime();

//Subtract and divide by 1 day (in milliseconds)
const diff = parseInt((t2 - t1) / (24 * 3600 * 1000), 10);

return `Sinds ${diff} ${diff > 1 ? 'dagen' : 'dag'} in main`;
}

function getChangesSinceLastRelease() {
const tag = executeCommandSync(
'git tag -l release-* --sort=-"version:refname"'
).slice(0, 16);
console.log(`Latest release tag found: ${tag}`);

const commitId = executeCommandSync(`git rev-list -n 1 ${tag}`);

const dateOfLastTag = executeCommandSync(
`git show -s --format=%ci ${commitId}`
);
console.log(`Date of last tag: ${dateOfLastTag}`);

const lines = executeCommandSync(
`git log --pretty="%s %cI" --no-merges --since="${dateOfLastTag}"`
);

const splitLines = lines.trim().split(/(?:\r\n|\r|\n)/g);
const jiraTicketRegex =
/(mijn(-| )\d+|bump!)([\s-]+)([a-zA-Z\s]+)\(#([\d]+)\)/gi;

return splitLines
.map((line) => {
if (line.startsWith(RELEASE_MERGE_MESSAGE)) {
return; // The release is merged after the release tag is created.
// So we might (should) encounter the previous release merge commit.
}

const match = jiraTicketRegex.exec(line.trim());

if (!!match) {
// each line is a commit message since the last release

return {
ticket: match[1].trim().replace(' ', '-'),
description: match[4],
pr: match[5],
date: getDateDiff(new Date(line.slice(-25))),
};
}
})
.filter(Boolean); // Filter empty entries
}

const changes = getChangesSinceLastRelease();
const cardJson = getReleaseCardJson(changes);
sendTeamsMessage(cardJson, process.env.webhook_host, process.env.webhook_path);
50 changes: 50 additions & 0 deletions scripts/release-notifications/teams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const https = require('https');

function sendTeamsMessage(cardJson, host, path) {
const post_data = JSON.stringify({
type: 'message',
attachments: [
{
contentType: 'application/vnd.microsoft.card.adaptive',
contentUrl: null,
content: cardJson,
},
],
});

const post_options = {
host,
port: 443,
path,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(post_data),
'User-Agent': 'nodejs',
},
};

try {
// Set up the request
const post_req = https.request(post_options, function (res) {
res.setEncoding('utf8');
res.on('error', function (err) {
console.error(err.stack);
process.exit();
});
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
});
});

post_req.write(post_data);
post_req.end();
} catch (e) {
console.error(e);
process.exit();
}
}

module.exports = {
sendTeamsMessage,
};