Skip to content

Commit 1501237

Browse files
✨ import enhancements done in trutificationdemo (#29)
- setting back the "cherry-pick" label for selecting backports. The reason is that there are other parts in the repository that rely on a pre-stablished "cherry-pick" label like for instance https://github.com/trustification/release-tools/blob/main/pkg/config/config.yaml#L96-L99 - The problem in the past seems to be that we could not find a regex that math the cherry-pick labels but while enhancing the trustificationdemo org I fixed it using ```yaml label_pattern: >- ^cherry-pick\/([^ ]+)$ ``` - Enhancing the Title verification error, now the GH log will contain which are the valid title prefixes. - Introduce the create-release reusable action for generating releases and changelogs
2 parents 675a642 + 06d676a commit 1501237

File tree

4 files changed

+101
-3
lines changed

4 files changed

+101
-3
lines changed

.github/workflows/cherry-pick.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jobs:
2323
const labels = issue.labels.map(label => label.name);
2424
console.log(`Labels: ${labels}`);
2525
26-
const branches = labels.filter(label => label.startsWith('backport '))
27-
.map(label => label.substr(9));
26+
const branches = labels.filter(label => label.startsWith('cherry-pick/'))
27+
.map(label => label.substr(12));
2828
console.log(`Branches: ${branches}`);
2929
3030
return branches
@@ -54,4 +54,6 @@ jobs:
5454
uses: korthout/backport-action@v3
5555
with:
5656
github_token: ${{ steps.get_workflow_token.outputs.token }}
57+
label_pattern: >-
58+
^cherry-pick\/([^ ]+)$
5759
pull_title: '${pull_title} [Backport ${target_branch}]'

cmd/verify-pr/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ struct PullRequestEvent {
1616
}
1717

1818
fn main() -> error::Result<()> {
19+
let result = verify_pr();
20+
match &result {
21+
Ok(_) => {}
22+
Err(error) => println!("{error}"),
23+
};
24+
result
25+
}
26+
27+
fn verify_pr() -> error::Result<()> {
1928
let gh_context = GitHubVariables::from_env()?;
2029

2130
// Parse the event

create-release/action.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Create Release
2+
description: Create a release in a project
3+
inputs:
4+
github_token:
5+
description: 'GitHub token'
6+
required: true
7+
version:
8+
description: 'Semantic version of the release (eg. v1.2.3 or v1.2.3-alpha.2)'
9+
required: true
10+
prev_version:
11+
description: 'Semantic version of the previous release (eg. v1.2.2 or v1.2.3-alpha.1)'
12+
required: false
13+
default: ''
14+
repository:
15+
description: 'The repository where the release should be created'
16+
required: false
17+
default: ${{ github.repository }}
18+
ref:
19+
description: 'The branch or SHA for the release (defaults to main)'
20+
required: false
21+
default: ${{ github.ref }}
22+
is_prerelease:
23+
description: 'Is this a pre-release?'
24+
required: false
25+
default: "false"
26+
27+
runs:
28+
using: "composite"
29+
steps:
30+
- name: Verify tag is semver
31+
shell: bash
32+
run: |
33+
set -x
34+
if [[ ! "${{ inputs.version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then
35+
echo "This is not a semver compliant tag"
36+
echo "Exiting"
37+
exit 1
38+
fi
39+
40+
if [[ "${{ inputs.version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
41+
echo "is_prerelease=false" >> $GITHUB_OUTPUT
42+
else
43+
echo "is_prerelease=true" >> $GITHUB_OUTPUT
44+
fi
45+
46+
if [[ "${{ inputs.version }}" =~ ^v[0-9]+\.[0-9]+\.0$ ]]; then
47+
echo "is_dotzero=true" >> $GITHUB_OUTPUT
48+
else
49+
echo "is_dotzero=false" >> $GITHUB_OUTPUT
50+
fi
51+
52+
XY_VERSION=$(echo ${{ inputs.version }} | awk -F. '{print substr($1,2)"."$2}')
53+
echo "xy_version=${XY_VERSION}" >> $GITHUB_OUTPUT
54+
id: check_tag
55+
56+
- name: Checkout code
57+
uses: actions/checkout@v4
58+
59+
- name: Generate Changelog
60+
uses: ./.github/workflows/generate-changelog.yml
61+
with:
62+
version: ${{ github.event.inputs.version }}
63+
prev_version: ${{ github.event.inputs.prev_version }}
64+
repository: ${{ github.event.inputs.repository }}
65+
ref: ${{ github.event.inputs.ref }}
66+
github_token: ${{ inputs.github_token }}
67+
68+
- name: Download Changelog
69+
uses: actions/download-artifact@v4
70+
with:
71+
name: changelog-artifact
72+
path: .
73+
74+
75+
- uses: ncipollo/release-action@main
76+
with:
77+
owner: ${{ github.repository_owner }}
78+
repo: ${{ inputs.repository }}
79+
tag: ${{ inputs.version }}
80+
commit: ${{ github.sha }}
81+
bodyFile: release.md
82+
draft: false
83+
prerelease: ${{ inputs.is_prerelease }}
84+
skipIfReleaseExists: true
85+
token: ${{ inputs.github_token }}

pkg/pr/src/error.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ pub type Result<T> = std::result::Result<T, Error>;
22

33
#[derive(Debug, PartialEq, thiserror::Error)]
44
pub enum Error {
5-
#[error("Invalid prefix (title {title:?}, emoji {emoji:?})")]
5+
#[error(
6+
"Invalid prefix (title: {title}, emoji: {emoji:#?}).\nValid prefixes are:\n:sparkles:\n:bug:\n:book:\n:seedling:\n:warning:\n:ghost:\n"
7+
)]
68
InvalidTitle {
79
title: String,
810
emoji: Option<String>,

0 commit comments

Comments
 (0)