-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (164 loc) · 6.15 KB
/
release-app.yml
File metadata and controls
174 lines (164 loc) · 6.15 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# This workflow will be able to manage:
# - creation of a release branch
# - create a PR to main and develop
#
# The workflow will need an input type choice with this list as options
# - nothing (it's a security in case user valid exec without checking this option)
# - major
# - premajor
# - minor
# - preminor
# - patch
# - prepatch
# - prerelease
#
# If you want to add a manual action to approve the creation of the release, you need to create an environment 'Need Review' and set a list of reviewer in your repository settings
#
# On PR created by the workflow, it's recommanded to use merge action instead of squash to keep main and develop sync to keep history between both
name: Release - App
on:
workflow_call:
inputs:
scope:
description: "Release scope"
type: string
default: nothing
required: true
workflow_dispatch:
inputs:
scope:
description: "Release scope"
type: choice
default: nothing
required: true
options:
- nothing
- major
- premajor
- minor
- preminor
- patch
- prepatch
- prerelease
jobs:
display-inputs:
runs-on: ubuntu-latest
steps:
- name: Display inputs
run: |
echo "Github event ref branch : ${{ github.event.ref }}"
echo "Github actor : $GITHUB_ACTOR"
echo "Github branch : ${GITHUB_REF#refs/heads/}"
echo "Release scope : ${{ github.event.inputs.scope }}"
create-release:
environment: Need Review
runs-on: ubuntu-latest
outputs:
releasebranch: ${{ steps.release.outputs.releasebranch }}
releaseVersion: ${{ steps.release.outputs.releaseVersion }}
steps:
- name: Error - Missing scope
if: |
github.event.inputs.scope != 'major' &&
github.event.inputs.scope != 'premajor' &&
github.event.inputs.scope != 'minor' &&
github.event.inputs.scope != 'preminor' &&
github.event.inputs.scope != 'patch' &&
github.event.inputs.scope != 'prepatch' &&
github.event.inputs.scope != 'prerelease'
run: |
echo "Release scope not well defined (use 'major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch' or 'prerelease'"
exit 1
- name: Checkout repository
uses: actions/checkout@v3
with:
# fetch-depth: to be able to detect diff between release branch and main branch
fetch-depth: 0
ref: ${{ github.event.ref }}
- name: setup git config
run: |
# git config user.name "Release Bot"
# git config user.email "<>"
git config user.name $GITHUB_ACTOR
git config user.email gh-actions-${GITHUB_ACTOR}@github.com
- name: Create release branch and tag
id: release
run: |
echo "Create release from ${{ github.event.ref }} to a new release branch and create tag"
npm version ${{ github.event.inputs.scope }} --no-git-tag-version > release.version
echo "::set-output name=releaseVersion::$(cat release.version)"
echo "::set-output name=releasebranch::release_$(cat release.version)"
git branch release_$(cat release.version)
git checkout release_$(cat release.version)
git add package.json
git commit -m "Release $(cat release.version)"
git push origin release_$(cat release.version)
git tag -a $(cat release.version) -m "Release $(cat release.version)"
git push origin --tags
echo "Release from ${{ github.event.ref }} to ${{ github.event.inputs.release_branch }} created"
echo "Release tag $(cat release.version) created"
- name: Generate release tag
if: steps.release.outputs.releaseVersion
uses: Roang-zero1/github-create-release-action@master
with:
created_tag: ${{ steps.release.outputs.releaseVersion }}
version_regex: ^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+
prerelease_regex: "^v[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+-[[:digit:]]"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
create-pr-develop:
#environment: Need Review
runs-on: ubuntu-latest
needs: [create-release]
steps:
- name: Create pull request to develop
uses: actions/github-script@v6
with:
script: |
const { repo, owner } = context.repo;
const result = await github.rest.pulls.create({
title: '[Develop] Release ${{ needs.create-release.outputs.releaseVersion }} ',
owner,
repo,
head: '${{ needs.create-release.outputs.releasebranch}}',
base: 'develop',
body: [
'## Release ${{ needs.create-release.outputs.releaseVersion }}',
].join('\n')
});
github.rest.issues.addLabels({
owner,
repo,
issue_number: result.data.number,
labels: ['release', 'automated pr']
});
create-pr-main:
#environment: Need Review
runs-on: ubuntu-latest
needs: [create-release, create-pr-develop]
steps:
- name: Create pull request to main
if: |
github.event.inputs.scope == 'patch' ||
github.event.inputs.scope == 'minor' ||
github.event.inputs.scope == 'major'
uses: actions/github-script@v6
with:
script: |
const { repo, owner } = context.repo;
const result = await github.rest.pulls.create({
title: '[Main] Release ${{ needs.create-release.outputs.releaseVersion }} ',
owner,
repo,
head: '${{ needs.create-release.outputs.releasebranch}}',
base: 'main',
body: [
'## Release ${{ needs.create-release.outputs.releaseVersion }}',
].join('\n')
});
github.rest.issues.addLabels({
owner,
repo,
issue_number: result.data.number,
labels: ['release', 'automated pr']
});