Skip to content

Commit 84e5313

Browse files
Tecnobutrulpabloelcolombiano
authored andcommitted
PB-24575: release notes automations
1 parent fdfb13a commit 84e5313

15 files changed

+313
-3
lines changed

.github/workflows/release.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Create Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+'
7+
8+
jobs:
9+
build:
10+
name: Create release
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- env:
15+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
16+
name: Create Release
17+
run: gh release create "${GITHUB_REF#refs/*/}" --notes-file RELEASE_NOTES.md
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Create Release Candidate
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+'
7+
8+
jobs:
9+
build:
10+
name: Create release candidate
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- env:
15+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
16+
name: Create Release candidate
17+
run: gh release create "${GITHUB_REF#refs/*/}" -p --notes-file RELEASE_NOTES.md

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,5 @@ tilt_modules*
132132

133133
# PHPUNIT generated file
134134
.phpunit.result.cache
135+
# Vim filems
136+
*.vim

.gitlab-ci.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ stages:
1818
- unit-test
1919
- unit-test-parallel
2020
- packaging-trigger
21+
- release
2122

2223
include:
2324
- template: Code-Quality.gitlab-ci.yml
24-
# - local: "/.gitlab-ci/jobs/php_unit_tests/runner.yml"
25+
# - local: "/.gitlab-ci/jobs/php_unit_tests/runner.yml"
2526
- local: "/.gitlab-ci/jobs/php_unit_tests/sequential/php_unit_tests.yml"
2627
- local: "/.gitlab-ci/jobs/style_check.yml"
2728
- local: "/.gitlab-ci/jobs/security_check.yml"
2829
- local: ".gitlab-ci/jobs/packaging_trigger/package_trigger.yml"
30+
- local: ".gitlab-ci/jobs/release.yml"
31+
- local: ".gitlab-ci/jobs/help_site_notes.yml"
2932

3033
code_quality:
3134
stage: unit-test

.gitlab-ci/jobs/help_site_notes.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
help_site_notes:
2+
stage: release
3+
variables:
4+
GPG_KEY_PATH: "/tmp/gpg-key"
5+
GPG_PASSPHRASE: $HELP_SITE_GPG_KEY_PASS
6+
GPG_KEY_GRIP: $HELP_SITE_GPG_KEYGRIP
7+
image: debian
8+
script: |
9+
source .gitlab-ci/scripts/bin/set-env.sh "$CI_COMMIT_TAG"
10+
if is_release_candidate "$tag"; then
11+
echo "The tag is for a release candidate. Skipping release notes creation..."
12+
exit 0
13+
fi
14+
apt update && apt install -y git curl gpg
15+
curl -L https://gitlab.com/gitlab-org/cli/-/releases/v1.30.0/downloads/glab_1.30.0_Linux_x86_64.deb --output glab.deb
16+
dpkg -i glab.deb
17+
cat "$HELP_SITE_GPG_KEY" > "$GPG_KEY_PATH"
18+
bash .gitlab-ci/scripts/bin/help_site.sh
19+
rules:
20+
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
21+
when: on_success

.gitlab-ci/jobs/packaging_trigger/package_trigger.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ packaging-trigger:
33
variables:
44
PACKAGING_TRIGGER_BRANCH: "main"
55
DOWNSTREAM_PROJECT_ID: "$PACKAGING_PROJECT_ID"
6-
image: registry.gitlab.com/passbolt/passbolt-ci-docker-images/debian-bullseye-11-slim:latest
6+
image: debian:bullseye-slim
77
script:
88
- apt update && apt install -y curl
9-
- bash .gitlab-ci/scripts/packaging-trigger.sh "$CI_COMMIT_TAG" "$PACKAGING_TRIGGER_BRANCH"
9+
- bash .gitlab-ci/scripts/bin/packaging-trigger.sh "$CI_COMMIT_TAG" "$PACKAGING_TRIGGER_BRANCH"
1010
rules:
1111
- if: $CI_COMMIT_TAG
1212
when: on_success

.gitlab-ci/jobs/release.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
release_notes:
2+
image: registry.gitlab.com/gitlab-org/release-cli:latest
3+
release:
4+
description: './RELEASE_NOTES.md'
5+
tag_name: $CI_COMMIT_TAG
6+
rules:
7+
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
8+
when: on_success
9+
script: echo "Creating relase notes for $CI_COMMIT_TAG"
10+
stage: release
11+
12+
release_notes_candidate:
13+
image: registry.gitlab.com/gitlab-org/release-cli:latest
14+
release:
15+
tag_name: $CI_COMMIT_TAG
16+
description: $CI_COMMIT_TAG
17+
rules:
18+
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+$/'
19+
when: on_success
20+
script: echo "Creating relase notes for $CI_COMMIT_TAG"
21+
stage: release

.gitlab-ci/scripts/bin/help_site.sh

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
#
3+
4+
set -euo pipefail
5+
6+
CI_SCRIPTS_DIR=$(dirname "$0")/..
7+
8+
# shellcheck source=.gitlab-ci/scripts/lib/git-helpers.sh
9+
source "$CI_SCRIPTS_DIR"/lib/git-helpers.sh
10+
11+
PASSBOLT_HELP_DIR="passbolt_help"
12+
GITLAB_USER_EMAIL="[email protected]"
13+
GIT_CI_TOKEN_NAME=${GIT_CI_TOKEN_NAME:-gitlab-ci-token}
14+
ACCESS_TOKEN_NAME="help-site-bot"
15+
HELP_SITE_REPO="gitlab.com/passbolt/passbolt-help.git"
16+
RELEASE_NOTES_PATH="../RELEASE_NOTES.md"
17+
18+
19+
function create_release_notes() {
20+
title="$(grep name ../config/version.php | awk -F "'" '{print $4}')"
21+
slug="$(grep name ../config/version.php | awk -F "'" '{print $4}' | tr ' ' '_' | tr '[:upper:]' '[:lower:]')"
22+
categories="releases $PASSBOLT_FLAVOUR"
23+
song="$(grep 'Release song:' $RELEASE_NOTES_PATH | awk '{print $3}')"
24+
quote="$(grep name ../config/version.php | awk -F "'" '{print $4}')"
25+
permalink="/releases/$PASSBOLT_FLAVOUR/$(grep name ../config/version.php | awk -F "'" '{print $4}' | tr ' ' '_' | tr '[:upper:]' '[:lower:]')"
26+
date="$(date +'%Y-%m-%d')"
27+
28+
cat << EOF >> _releases/"$PASSBOLT_FLAVOUR"/"$CI_COMMIT_TAG".md
29+
---
30+
title: $title
31+
slug: $slug
32+
layout: release
33+
categories: $categories
34+
version: $CI_COMMIT_TAG
35+
product: $PASSBOLT_FLAVOUR
36+
song: $song
37+
quote: $quote
38+
permalink: $permalink
39+
date: $date
40+
---
41+
EOF
42+
43+
cat $RELEASE_NOTES_PATH >> _releases/"$PASSBOLT_FLAVOUR"/"$CI_COMMIT_TAG".md
44+
}
45+
46+
setup_gpg_key "$GPG_KEY_PATH" "$GPG_PASSPHRASE" "$GPG_KEY_GRIP"
47+
setup_git_user "$GITLAB_USER_EMAIL" "$ACCESS_TOKEN_NAME"
48+
49+
git clone -b master https://"$HELPSITE_TOKEN_NAME":"$HELPSITE_TOKEN"@"$HELP_SITE_REPO" "$PASSBOLT_HELP_DIR"
50+
51+
cd "$PASSBOLT_HELP_DIR"
52+
53+
create_release_notes
54+
git checkout -b release_notes_"$CI_COMMIT_TAG"
55+
git add _releases/"$PASSBOLT_FLAVOUR"/"$CI_COMMIT_TAG".md
56+
git commit -m ":robot: Automatically added release notes for version $CI_COMMIT_TAG $PASSBOLT_FLAVOUR"
57+
glab auth login --token "$HELPSITE_TOKEN"
58+
mr_url=$(glab mr create -s release_notes_"$CI_COMMIT_TAG" -b master -d ":robot: Release notes for $CI_COMMIT_TAG $PASSBOLT_FLAVOUR" -t "Release notes for $CI_COMMIT_TAG" --push --repo "passbolt/passbolt-help" | grep 'https://gitlab.com/passbolt/passbolt-help/-/merge_requests/')
59+
cd -
60+
bash .gitlab-ci/scripts/bin/slack-status-messages.sh ":notebook: New helpsite release notes created for $CI_COMMIT_TAG $PASSBOLT_FLAVOUR" "$mr_url"

.gitlab-ci/scripts/bin/set-env.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# shellcheck disable=SC1091
4+
5+
CI_SCRIPTS_DIR=$(dirname "$BASH_SOURCE")/..
6+
7+
source "$CI_SCRIPTS_DIR"/lib/version-check.sh
8+
source "$CI_SCRIPTS_DIR"/lib/set-env.sh
9+
10+
declare -a version_config
11+
tag="$1"
12+
13+
if [[ $tag == "" ]]; then
14+
# If we don't have a tag we check for specific commit message to set
15+
# parse_commit_message returns by default: release pro all testing
16+
# branch and flavour
17+
read -r -a version_config <<< "$(parse_commit_message "$CI_COMMIT_MESSAGE")"
18+
else
19+
# This line doesn't work on zsh shell
20+
read -r -a version_config <<< "$(parse_tag "$tag")"
21+
fi
22+
23+
echo "Exporting the following variables"
24+
echo "================================="
25+
echo "API_CLONE_BRANCH=${version_config[0]}"
26+
echo "PASSBOLT_FLAVOUR=${version_config[1]}"
27+
echo "FILTER=${version_config[2]}"
28+
echo "PASSBOLT_COMPONENT=${version_config[3]}"
29+
30+
export API_CLONE_BRANCH="${version_config[0]}"
31+
export PASSBOLT_FLAVOUR="${version_config[1]}"
32+
export FILTER="${version_config[2]}"
33+
export PASSBOLT_COMPONENT="${version_config[3]}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
# Variables required
4+
# CI_PROJECT_NAME
5+
# CI_PIPELINE_ID
6+
# SLACK_CHANNEL_ID
7+
# SLACK_WEBHOOK
8+
9+
title="$1"
10+
url="$2"
11+
12+
curl -X POST -H 'Content-type: application/json' $SLACK_WEBHOOK \
13+
--data-binary @- <<EOF
14+
{
15+
"channel": "$SLACK_CHANNEL_ID",
16+
"attachments": [
17+
{
18+
"color": "#36A64F",
19+
"title": "$title",
20+
"attachment_type": "default",
21+
"actions": [
22+
{
23+
"name": "Check it!",
24+
"text": "Check it!",
25+
"type": "button",
26+
"style": "primary",
27+
"url": "$url"
28+
}
29+
]
30+
}
31+
]
32+
}
33+
EOF

.gitlab-ci/scripts/lib/git-helpers.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function setup_gpg_key() {
2+
key_path="$1"
3+
passphrase="$2"
4+
grip="$3"
5+
6+
mkdir -p ~/.gnupg
7+
echo "allow-preset-passphrase" > ~/.gnupg/gpg-agent.conf
8+
gpg-agent --homedir ~/.gnupg --use-standard-socket --daemon
9+
/usr/lib/gnupg2/gpg-preset-passphrase -c "$grip" <<< "$passphrase"
10+
gpg --pinentry-mode loopback --passphrase "$passphrase" --import "$key_path"
11+
}
12+
13+
function setup_git_user() {
14+
local email="$1"
15+
local name="$2"
16+
git config --global user.email "$email"
17+
git config --global user.name "$name"
18+
git config --global commit.gpgsign true
19+
git config --global user.signingkey "$email"
20+
}
21+
22+
function create_git_tag() {
23+
local passbolt_version="$1"
24+
local passbolt_flavour="$2"
25+
local filter="$3"
26+
local component="$4"
27+
local tag="$passbolt_version-$passbolt_flavour-$filter"
28+
git tag -a "$tag" -m "Release $tag version for $component package" > /dev/null
29+
}

.gitlab-ci/scripts/lib/set-env.sh

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This function parses a tag in the form of:
2+
# v3.11.0-rc.1-pro-all
3+
#
4+
# All of the fields are mandatory:
5+
# Version: v3.11.0-rc.1|v3.11.0
6+
# Passbolt flavour: pro|ce
7+
# Per package filter: all|rpm|debian
8+
#
9+
# It also provides the component based on if it is RC: testing|stable
10+
function parse_tag() {
11+
local tag=$1
12+
13+
if is_release_candidate "$tag"; then
14+
echo "$tag" | awk -F '-' '{print $1"-"$2,$3,$4,"testing"}'
15+
else
16+
echo "$tag" | awk -F '-' '{print $1,$2,$3,"stable"}'
17+
fi
18+
}
19+
20+
# Example [branch: develop] # points to pro flavour
21+
# Example [flavour: ce] # points to release branch
22+
# Example [branch: develop, flavour: ce]
23+
#
24+
# If the commit message does not contain any of the above patterns
25+
# We default to clone: pro api release branch
26+
function parse_commit_message() {
27+
local message="$1"
28+
local branch
29+
local flavour
30+
local component
31+
local filter
32+
33+
branch=$(calculate_regex "$message" "release" "branch")
34+
component=$(calculate_regex "$message" "testing" "component")
35+
filter=$(calculate_regex "$message" "all" "filter")
36+
flavour=$(calculate_regex "$message" "pro" "flavour")
37+
38+
echo "$branch" "$flavour" "$filter" "$component"
39+
}
40+
41+
function calculate_regex() {
42+
local message="$1"
43+
local default_value="$2"
44+
local pattern="$3"
45+
46+
result="$(echo "$message" | sed -nE "s/.*\[.*($pattern: *)([^]|^ |^,]+).*\]/\\2/p")"
47+
echo "${result:-$default_value}"
48+
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function is_valid_api_tag () {
2+
if [[ ! $PASSBOLT_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
3+
echo "Invalid version format: $PASSBOLT_VERSION"
4+
return 1
5+
fi
6+
}
7+
8+
function is_release_candidate () {
9+
local version=$1
10+
if [[ ! $version =~ [0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+ ]];then
11+
return 1
12+
fi
13+
return 0
14+
}
15+
16+
function validate_config_version_and_api_tag () {
17+
local version_file="$1"
18+
local version
19+
version=$(echo "$PASSBOLT_VERSION" | tr -d 'v')
20+
21+
if ! grep -q "$version" "$version_file"; then
22+
echo "Version number in version.php does not match the tag: $PASSBOLT_VERSION"
23+
return 1
24+
fi
25+
}
26+

RELEASE_NOTES.md

Whitespace-only changes.

0 commit comments

Comments
 (0)