-
Notifications
You must be signed in to change notification settings - Fork 20
134 lines (111 loc) · 4.78 KB
/
release-cut.yml
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
name: Release Cut
on:
workflow_dispatch:
inputs:
release-type:
description: Release type (major/minor/patch/premajor/preminor/prerelease/prepatch)
required: true
branch-name:
description: Branch name (Optional), defaults to main
required: false
default: main
npm-release:
type: boolean
description: Toggle for NPM package release (Optional), defaults to false
required: false
default: false
pre-id:
description: Prerelease id (Optional), defaults to beta
required: false
default: beta
dry-run:
type: boolean
description: Runs NPM publish with the --dry-run flag to prevent publication, defaults to false
required: false
default: false
tag:
type: choice
description: The tag to publish to in NPM. e.g. latest or beta
default: "latest"
required: true
options:
- latest
- alpha
- beta
jobs:
cut-release:
if: contains('["0x0Koda", "rajat43", "jmdev3", "odcey"]', github.actor)
name: Create release branch and PRs into develop/main
runs-on: ubuntu-latest
steps:
- name: Exit if release type argument is invalid
run: exit 1
if: ${{ !contains('["major","minor", "patch", "premajor", "preminor", "prerelease", "prepatch"]', github.event.inputs.release-type) }}
- name: Checkout ${{ github.event.inputs.branch-name }} for ${{ github.event.inputs.release-type }} release
uses: actions/checkout@v3
if: ${{ github.event.inputs.branch-name != 'main' }}
with:
ref: ${{ github.event.inputs.branch-name }}
node-version: 18.x
fetch-depth: 0
- name: Checkout main for ${{ github.event.inputs.release-type }} release
uses: actions/checkout@v3
if: ${{ github.event.inputs.branch-name == 'main' }}
with:
ref: main
node-version: 18.x
fetch-depth: 0
- name: Authenticate with private NPM package
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: Install dependencies
run: |
yarn install --immutable --immutable-cache --check-cache --network-concurrency 1
yarn build
- name: Setup git profile
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Create release branch and generate PR body
id: create-release
env:
RELEASE_TYPE: ${{ github.event.inputs.release-type }}
PRE_ID: ${{ github.event.inputs.pre-id }}
run: |
current_version=$(jq -r .version package.json)
npm version $RELEASE_TYPE --preid $PRE_ID --git-tag-version false
new_version=$(jq -r .version package.json)
git reset --hard
branch_name="release/v${new_version}"
echo "Current version is $current_version"
echo "New version is $new_version"
echo "New branch name is $branch_name"
git checkout -b "$branch_name"
# Run release-ci command
yarn release:ci --i $RELEASE_TYPE --preReleaseId $PRE_ID --no-git.requireUpstream
git push --set-upstream origin "$branch_name"
# Use --depth to get commits to add to rev-list
git fetch origin ${{ github.event.inputs.branch-name }} --depth 100
main_pr_body=$(git rev-list --oneline $branch_name ^origin/${{ github.event.inputs.branch-name }})
echo 'main_pr_body<<END_OF_OUTPUT' >> $GITHUB_ENV
echo "$main_pr_body" >> $GITHUB_ENV
echo 'END_OF_OUTPUT' >> $GITHUB_ENV
echo "::set-output name=branch_name::$branch_name"
- name: Create pull request into ${{ github.event.inputs.branch-name }}
uses: repo-sync/pull-request@v2
with:
source_branch: ${{ steps.create-release.outputs.branch_name }}
destination_branch: "${{ github.event.inputs.branch-name }}"
github_token: ${{ secrets.GITHUB_TOKEN }}
pr_title: ${{ steps.create-release.outputs.branch_name }}
pr_body: ${{ env.main_pr_body }}
- name: Publish to NPM
id: publish
uses: JS-DevTools/npm-publish@v1
if: ${{ github.event.inputs.npm-release == 'true' }}
with:
token: ${{ secrets.NPM_TOKEN }}
dry-run: ${{ github.event.inputs.dry-run }}
tag: ${{github.event.inputs.tag}}
- if: ${{ github.event.inputs.npm-release == 'true' && steps.publish.outputs.type != 'none' && github.event.inputs.dry-run == 'false'}}
run: |
echo "Version changed: ${{ steps.publish.outputs.old-version }} => ${{ steps.publish.outputs.version }}"