-
Notifications
You must be signed in to change notification settings - Fork 91
153 lines (137 loc) · 5.08 KB
/
release.yaml
File metadata and controls
153 lines (137 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
---
name: release
run-name: Release ${{ inputs.tag }}
on:
workflow_dispatch:
inputs:
tag:
description: Tag
required: true
artifacts-name:
description: Artifacts name to promote (optional - will be auto-detected if not provided)
required: false
jobs:
verify-release:
name: Verify if tag is valid
runs-on: ubuntu-24.04
outputs:
artifacts-name: ${{ steps.get-artifacts-name.outputs.artifacts-name }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true
- name: Fetch tags
run: git fetch --tags
- name: Check if tag matches the branch name
shell: bash
run: |
if [[ "${{ github.event.inputs.tag }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+-[0-9]+$ ]]; then
# Hotfix release: extract base version from tag (e.g., 2.13.5 from 2.13.5.1)
[[ "refs/heads/hotfix/${{ github.event.inputs.tag }}" == "${{ github.ref }}-"* ]]
elif [[ "${{ github.event.inputs.tag }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]]; then
# Regular release: tag must match branch name
[[ "refs/heads/development/${{ github.event.inputs.tag }}" == "${{ github.ref }}."* ]]
else
echo "Error: Tag must be in format X.Y.Z(-<prerelease>) or X.Y.Z-N (hotfix)"
exit 1
fi
- name: Check if tag matches VERSION file
shell: bash
run: |
source VERSION
# Direct match (handles regular releases and hotfix with VERSION_FULL=X.Y.Z.N)
[[ "${{ github.event.inputs.tag }}" == "$VERSION_FULL" ]]
- name: Check if tag has not already been created
shell: bash
run: |
! git show-ref --tags ${{ github.event.inputs.tag }} --quiet
- name: Auto-derive artifacts name if not provided
uses: actions/github-script@v7
id: get-artifacts-name
with:
script: |
const { getBuildArtifact } = require('./.github/scripts/get-build-artifact');
const artifactsName = process.env.ARTIFACTS_NAME
|| await getBuildArtifact(github, context, core);
core.setOutput('artifacts-name', artifactsName);
env:
ARTIFACTS_NAME: ${{ github.event.inputs.artifacts-name }}
release:
name: Release
runs-on: ubuntu-24.04
needs:
- verify-release
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check if version is a pre-release
shell: bash
run: |
source VERSION
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "VERSION_PRERELEASE=${VERSION_PRERELEASE}" >> $GITHUB_ENV
- name: Generate release notes
uses: actions/github-script@v7
with:
script: |
// Get all releases
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
});
// Convert semver-compliant hotfix tags (e.g., 2.13.5-1) to 4-digits format for comparison
let tag = context.payload.inputs.tag;
const hotfixMatch = tag.match(/^(\d+\.\d+\.\d+)-(\d+)$/);
if (hotfixMatch) {
tag = `${hotfixMatch[1]}.${hotfixMatch[2]}`;
}
// Get the previous release tag
const { getPreviousTag } = require('./.github/scripts/get-previous-tag');
const previous_tag = getPreviousTag(context.payload.inputs.tag, releases);
if (!previous_tag) {
core.warning("No previous version found");
return;
}
// Generate release notes
const { data: releaseNotes } = await github.rest.repos.generateReleaseNotes({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: context.payload.inputs.tag,
target_commitish: context.sha,
previous_tag_name: previous_tag,
});
core.exportVariable('RELEASE_NOTES', releaseNotes.body);
- name: Create Release
uses: softprops/action-gh-release@v2.5.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: Release ${{ github.event.inputs.tag }}
tag_name: ${{ github.event.inputs.tag }}
generate_release_notes: false
body: ${{ env.RELEASE_NOTES }}
target_commitish: ${{ github.sha }}
prerelease: ${{ env.VERSION_PRERELEASE != '' }}
promote:
runs-on: ubuntu-24.04
needs:
- verify-release
- release
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Promote artifacts
uses: scality/action-artifacts@v4
with:
method: promote
name: ${{ needs.verify-release.outputs.artifacts-name }}
tag: ${{ github.event.inputs.tag }}
url: https://artifacts.scality.net
user: ${{ secrets.ARTIFACTS_USER }}
password: ${{ secrets.ARTIFACTS_PASSWORD }}