-
Notifications
You must be signed in to change notification settings - Fork 20
166 lines (145 loc) · 5.66 KB
/
release_workspace.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
156
157
158
159
160
161
162
163
164
165
166
name: Release workspace
on:
workflow_dispatch:
inputs:
workspace:
description: "Name of the Workspace"
required: true
type: string
force_release:
description: "Force release even if no changesets are present"
required: false
type: boolean
branch:
description: "Branch to run the workflow on"
required: false
default: "main"
type: string
workflow_call:
inputs:
force_release:
description: "Force release even if no changesets are present"
required: false
type: boolean
workspace:
description: "Name of the Workspace"
required: true
type: string
branch:
description: "Branch to run the workflow on"
required: false
default: "main"
type: string
concurrency:
group: ${{ github.workflow }}-${{ inputs.workspace }}
jobs:
changesets-pr:
name: Update Version Packages PR for ${{ inputs.workspace }} on branch ${{ inputs.branch }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./workspaces/${{ inputs.workspace }}
env:
CI: true
NODE_OPTIONS: --max-old-space-size=4096
outputs:
needs_release: ${{ steps.release_check.outputs.needs_release }}
steps:
- name: Checkout
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4
with:
ref: ${{ inputs.branch }}
- name: Set up Node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/ # Needed for auth
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles(format('workspaces/${0}/**/yarn.lock', inputs.workspace)) }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn install
run: yarn install --immutable
- name: Fetch previous commit for release check
run: git fetch origin '${{ github.event.before }}'
- name: Fetch the commit that triggered the workflow (used by backstage/changesets-action)
run: git fetch origin ${{ github.sha }}
continue-on-error: true
- name: Check if release
id: release_check
if: inputs.force_release != true
run: node ../../scripts/ci/check-if-release.js
env:
WORKSPACE_NAME: ${{ inputs.workspace }}
COMMIT_SHA_BEFORE: '${{ github.event.before }}'
TARGET_BRANCH: ${{inputs.branch}}
- name: Update Version Packages (${{ inputs.workspace }}) PR
id: changesets-pr
if: steps.release_check.outputs.needs_release != 'true' || inputs.force_release != true
uses: backstage/changesets-action@291bfc1f76d1dcfbf967f5810dc0423592eae09a # v2.3.1
with:
title: Version Packages (${{ inputs.workspace }})
cwd: workspaces/${{ inputs.workspace }}
version: yarn changeset version
versionBranch: changesets-release/${{ inputs.workspace }}/${{ inputs.branch }}
skipRootChangelogUpdate: true
env:
GITHUB_TOKEN: ${{ secrets.RHDH_BOT_TOKEN }}
release:
name: Release workspace ${{ inputs.workspace }} on branch ${{ inputs.branch }}
runs-on: ubuntu-latest
needs: changesets-pr
if: needs.changesets-pr.outputs.needs_release == 'true' || inputs.force_release == true
defaults:
run:
working-directory: ./workspaces/${{ inputs.workspace }}
env:
CI: true
NODE_OPTIONS: --max-old-space-size=4096
steps:
- name: Checkout
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4
with:
ref: ${{ inputs.branch }}
- name: Set up Node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/ # Needed for auth
- name: Install root dependencies
run: yarn install --immutable
working-directory: ${{ github.workspace }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles(format('workspaces/${0}/**/yarn.lock', inputs.workspace)) }}
restore-keys: |
${{ runner.os }}-yarn-
- name: yarn install
run: yarn install --immutable
- name: Compile TypeScript
run: yarn tsc:full
- name: Build all packages
run: yarn build:all
- name: publish
run: |
yarn config set -H 'npmAuthToken' "${{ secrets.RHDH_NPM_TOKEN }}"
yarn workspaces foreach -v --no-private npm publish --access public --tolerate-republish
env:
NODE_AUTH_TOKEN: ${{ secrets.RHDH_NPM_TOKEN }}
- name: Create tag
working-directory: ${{ github.workspace }}/scripts/ci
run: node create-tag.js
env:
WORKSPACE_NAME: ${{ inputs.workspace }}
GITHUB_TOKEN: ${{ secrets.RHDH_BOT_TOKEN}}