-
Notifications
You must be signed in to change notification settings - Fork 23
145 lines (115 loc) · 4.83 KB
/
release-publish.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
name: 'Release and publish Workflow'
on:
workflow_dispatch:
inputs:
create_release:
description: 'Create release'
required: true
type: boolean
default: true
publish_packages:
description: 'Publish npm packages'
required: true
type: boolean
default: true
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
outputs:
needs_release: ${{ steps.release_check.outputs.needs_release }}
strategy:
matrix:
node-version: [20.x]
env:
CI: true
NODE_OPTIONS: --max-old-space-size=4096
steps:
- name: Check of github.event.before
if: ${{ !github.event.inputs.create_release && !github.event.inputs.publish_packages }}
run: if [ '${{ github.event.before }}' = '0000000000000000000000000000000000000000' ]; then echo "::warning title=Missing github.event.before::You are running this CD workflow on a newly created branch. Release won't be created..."; fi
- name: Checkout repository
uses: actions/checkout@v4.1.4
- name: use node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4.0.2
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/ # Needed for auth
- name: yarn install --frozen-lockfile
uses: backstage/actions/yarn-install@v0.6.11
with:
cache-prefix: ${{ runner.os }}-v${{ matrix.node-version }}
- name: Fetch previous commit for release check
if: ${{ github.event.before != '0000000000000000000000000000000000000000' }}
run: git fetch origin '${{ github.event.before }}'
- name: Check if release
id: release_check
if: ${{ github.event.before != '0000000000000000000000000000000000000000' }}
run: node scripts/check-if-release.js
env:
COMMIT_SHA_BEFORE: '${{ github.event.before }}'
- name: validate config
run: yarn backstage-cli config:check --lax
- name: lint
run: yarn backstage-cli repo lint
- name: type checking and declarations
run: yarn tsc:full
- name: build
run: yarn backstage-cli repo build --all
- name: verify type dependencies
run: yarn lint:type-deps
# A separate release build that is only run for commits that are the result of merging the "Version Packages" PR
# We can't re-use the output from the above step, but we'll have a guaranteed node_modules cache and
# only run the build steps that are necessary for publishing
release:
needs: build
if: needs.build.outputs.needs_release == 'true' || github.event.inputs.create_release || github.event.inputs.publish_packages
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
env:
CI: 'true'
NODE_OPTIONS: --max-old-space-size=4096
steps:
- name: Checkout repository
uses: actions/checkout@v4.1.4
- name: use node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4.0.2
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/ # Needed for auth
- name: yarn install --frozen-lockfile
uses: backstage/actions/yarn-install@v0.6.11
with:
cache-prefix: ${{ runner.os }}-v${{ matrix.node-version }}
- name: build type declarations
run: yarn tsc:full
- name: build packages
run: yarn backstage-cli repo build
# Publishes current version of packages that are not already present in the registry
- name: publish
if: needs.build.outputs.needs_release == 'true' || github.event.inputs.publish_packages
run: |
yarn config set -H 'npmAuthToken' "${{secrets.NPM_TOKEN}}"
if [ -f ".changeset/pre.json" ]; then
yarn workspaces foreach --all --verbose --no-private npm publish --access public --tolerate-republish --tag next
else
yarn workspaces foreach --all --verbose --no-private npm publish --access public --tolerate-republish
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Grabs the version in the root package.json and creates a tag on GitHub
- name: Create a release tag
id: create_tag
if: needs.build.outputs.needs_release == 'true' || github.event.inputs.create_release
run: node scripts/create-release-tag.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Convert the newly created tag into a release with changelog information
- name: Create release on GitHub
if: needs.build.outputs.needs_release == 'true' || github.event.inputs.create_release
run: node scripts/create-github-release.js ${{ steps.create_tag.outputs.tag_name }} 1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}