-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (134 loc) · 6.71 KB
/
Copy pathcode-release_preview.yml
File metadata and controls
154 lines (134 loc) · 6.71 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
154
# SPDX-FileCopyrightText: 2026 INDUSTRIA DE DISEÑO TEXTIL S.A. (INDITEX S.A.)
# SPDX-License-Identifier: Apache-2.0
---
name: code-release-preview
concurrency:
group: release-preview
cancel-in-progress: true
on:
pull_request:
types: [labeled, synchronize, ready_for_review, opened]
branches: ["main", "main-*"]
env:
PR_HEAD_REF: ${{ github.head_ref }}
jobs:
check-changes-in-paths:
name: Check for changes in corresponding paths
runs-on: ubuntu-24.04
if: ${{ github.event.pull_request.draft == false || contains(join(github.event.pull_request.labels.*.name, ', '), 'release-type') || contains(join(github.event.pull_request.labels.*.name, ', '), 'release-preview') }}
outputs:
detected: ${{ steps.changes.outputs.paths }}
steps:
- name: Check for changed files in specific paths
id: changes
uses: dorny/paths-filter@ebc4d7e9ebcb0b1eb21480bb8f43113e996ac77a
with:
filters: |
paths:
- "package.json"
- "package-lock.json"
- "CHANGELOG.md"
- "src/**"
- "types/**"
- "example/**"
- ".github/workflows/code*"
release-preview:
name: Release Preview
needs: check-changes-in-paths
if: ${{ (contains(join(github.event.pull_request.labels.*.name, ', '), 'release-type') || contains(join(github.event.pull_request.labels.*.name, ', '), 'release-preview')) && needs.check-changes-in-paths.outputs.detected == 'true' }}
runs-on: ubuntu-24.04
steps:
- name: Checkout merge commit
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
fetch-depth: 0
persist-credentials: false
- name: Setup patch release type version
if: contains(github.event.pull_request.labels.*.name, 'release-type/hotfix') || contains(github.event.pull_request.labels.*.name, 'release-type/multi-hotfix') || contains(github.event.pull_request.labels.*.name, 'release-type/patch')
run: echo "RELEASE_VERSION=patch" >> "$GITHUB_ENV"
- name: Setup minor release type version
if: contains(github.event.pull_request.labels.*.name, 'release-type/minor')
run: echo "RELEASE_VERSION=minor" >> "$GITHUB_ENV"
- name: Setup major release type version
if: contains(github.event.pull_request.labels.*.name, 'release-type/major')
run: echo "RELEASE_VERSION=major" >> "$GITHUB_ENV"
- name: Check merge strategy
run: |
if [[ "$PR_HEAD_REF" == hotfix* && "${{ contains(github.event.pull_request.labels.*.name, 'release-type/multi-hotfix') }}" != "true" ]]; then
echo "MERGE_STRATEGY=Squash and Merge" >> "$GITHUB_ENV"
elif [[ "${{ vars.DEVELOPMENT_FLOW }}" == "trunk-based-development" ]]; then
echo "MERGE_STRATEGY=Squash and Merge" >> "$GITHUB_ENV"
else
echo "MERGE_STRATEGY=Create a merge commit" >> "$GITHUB_ENV"
fi
- name: Check if CHANGELOG.md has changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if git diff --quiet HEAD^ HEAD -- CHANGELOG.md; then
echo "::error title={No CHANGELOG.md changes}::{No CHANGELOG.md changes were found. Update the Unreleased section with the new changes.}"
gh pr comment ${{ github.event.number }} --repo "$GITHUB_REPOSITORY" --body "### :x: No CHANGELOG.md changes
No changes were found in CHANGELOG.md. Please update the Unreleased section with the changes that apply to this release."
exit 1
fi
- name: Update CHANGELOG.md
id: update-changelog
uses: release-flow/keep-a-changelog-action@74931dec7ecdbfc8e38ac9ae7e8dd84c08db2f32 # v3.0.0
with:
command: bump
version: ${{ env.RELEASE_VERSION }}
changelog: CHANGELOG.md
fail-on-empty-release-notes: false
keep-unreleased-section: true
tag-prefix: ""
- name: Add PR comment with release preview
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TASKS=$(awk -v version="${{ steps.update-changelog.outputs.version }}" '
BEGIN { capture=0; found_version=0 }
$0 ~ "## \\[" version "\\] -" { capture=1; found_version=1; print; next }
capture && $0 ~ /^## \[.*\] -/ { capture=0 }
capture { print }
END {
if (found_version) {
while ((getline line < "CHANGELOG.md") > 0) {
if (line ~ /^\[.*\]:/) {
print line
}
}
}
}
' CHANGELOG.md)
MESSAGE="
### :rocket: Release Preview Success
You are going to release the version **${RELEASE_VERSION}** with the following changes:
$TASKS
### 💡 Merge Strategy: $MERGE_STRATEGY
Remember to use the **'$MERGE_STRATEGY'** strategy to merge this Pull Request (\`$PR_HEAD_REF\` → \`${{ github.event.pull_request.base.ref }}\`).
"
gh pr comment ${{ github.event.number }} --repo "$GITHUB_REPOSITORY" --body "$(echo -e "$MESSAGE")"
release-preview-no-code-changes:
name: Add PR comment with configuration management information
needs: check-changes-in-paths
if: ${{ (contains(join(github.event.pull_request.labels.*.name, ', '), 'release-type') || contains(join(github.event.pull_request.labels.*.name, ', '), 'release-preview')) && needs.check-changes-in-paths.outputs.detected == 'false' }}
runs-on: ubuntu-24.04
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Add PR comment with release preview
run: |
gh pr comment ${{ github.event.number }} --repo "$GITHUB_REPOSITORY" --body "### :exclamation: This Pull Request will not trigger a release
No package, source, example, changelog, or code workflow changes were detected."
release-preview-no-release-labels:
name: Add PR comment with release information
needs: check-changes-in-paths
if: ${{ !contains(join(github.event.pull_request.labels.*.name, ', '), 'release-type') && needs.check-changes-in-paths.outputs.detected == 'true' && github.event.pull_request.draft == false && vars.DEVELOPMENT_FLOW != 'trunk-based-development' }}
runs-on: ubuntu-24.04
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Add PR comment with release preview
run: |
gh pr comment ${{ github.event.number }} --repo "$GITHUB_REPOSITORY" --body "### :exclamation: This Pull Request will not trigger a release
A Pull Request with no \`release-type/...\` labels will not trigger a release, so you need to label this PR if you want to create a release."