This repository has been archived by the owner on Feb 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
155 lines (123 loc) · 4.72 KB
/
version-or-release.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Version/Release
on:
push:
branches:
- dev
jobs:
changesets:
name: Create Versioning PR or Start Release Pipeline
runs-on: ubuntu-latest
if: github.repository == 'statelyai/xstate-viz'
outputs:
hasChangesets: ${{ steps.changesets.outputs.hasChangesets }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn'
- name: Install Dependencies
run: yarn install --frozen-lockfile
- name: Create Release Pull Request
id: changesets
uses: changesets/action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
create-temp-release-branch:
name: Create temporary release branch
runs-on: ubuntu-latest
needs: changesets
if: needs.changesets.outputs.hasChangesets == 'false'
outputs:
release-branch: ${{ steps.release-branch-check.outputs.branch }}
version: ${{ steps.latest-version.outputs.result }}
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Get latest version
id: latest-version
uses: actions/github-script@v4
with:
result-encoding: string
script: return require('./package.json').version
- name: Check if branch for ${{ steps.latest-version.outputs.result }} is already created
id: release-branch-check
run: |
branch=release-temp-${{ steps.latest-version.outputs.result }}
if [ "$(git ls-remote https://github.com/${{ github.repository }}.git $branch)" == "" ]; then
echo "$branch doesn't exist on the remote"
echo "::set-output name=branch::$branch"
else
echo "$branch already exists on the remote"
fi;
# can't use the output from the previous step in the name here as it could have not been set
- name: Create release-temp-${{ steps.latest-version.outputs.result }} branch
if: steps.release-branch-check.outputs.branch
run: |
git push origin HEAD:${{ steps.release-branch-check.outputs.branch }}
staging-deploy-trigger:
name: Push release to staging
runs-on: ubuntu-latest
needs: create-temp-release-branch
if: needs.create-temp-release-branch.outputs.release-branch
environment: Staging Trigger
steps:
- name: Checkout Repo
uses: actions/checkout@v2
with:
ref: ${{ needs.create-temp-release-branch.outputs.release-branch }}
- name: Setup git user
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create release commit
run: |
git commit -m 'Release ${{ needs.create-temp-release-branch.outputs.version }} to staging' --allow-empty
- name: Force push the release to staging
run: |
git push origin HEAD:staging --force
production-deploy-trigger:
name: Push release to main
runs-on: ubuntu-latest
needs: create-temp-release-branch
if: needs.create-temp-release-branch.outputs.release-branch
environment: Production Trigger
steps:
- name: Checkout Repo
uses: actions/checkout@v2
with:
ref: ${{ needs.create-temp-release-branch.outputs.release-branch }}
- name: Setup git user
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create release commit
run: |
git commit -m 'Release ${{ needs.create-temp-release-branch.outputs.version }} to main' --allow-empty
- name: Force push the release to main
run: |
git push origin HEAD:main --force
create-github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [create-temp-release-branch, production-deploy-trigger]
steps:
- name: Checkout Repo
uses: actions/checkout@v2
with:
ref: ${{ needs.create-temp-release-branch.outputs.release-branch }}
- name: Publish a tag
run: |
git tag v${{ needs.create-temp-release-branch.outputs.version }}
git push origin v${{ needs.create-temp-release-branch.outputs.version }}
- name: Publish a GitHub release
uses: actions/github-script@v4
with:
script: |
const { publishRelease } = require(`./scripts/publish-github-release.js`)
await publishRelease(github, { repo: context.repo })
- name: Remove the temporary release branch
run: |
git push origin --delete ${{ needs.create-temp-release-branch.outputs.release-branch }}