-
Notifications
You must be signed in to change notification settings - Fork 2
157 lines (154 loc) · 6.62 KB
/
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
156
157
name: Release
# concurrency: Ensures that for one branch the workflow is not running multiple
# times at the same time as we will get trouble with the versions and pushes.
concurrency: ci-${{ github.ref }}
on:
push:
branches:
- main
- 'maintenance/**'
workflow_dispatch:
inputs:
release_type:
description: 'Release type.'
required: true
default: 'patch'
type: choice
options:
- major
- minor
- patch
permissions:
contents: write
env:
NODE_VERSION: 20
# https://github.com/actions/runner-images/issues/70
NODE_OPTIONS: "--max_old_space_size=4096"
PNPM_VERSION: ^9.4
NPM_CONFIG_@coremedia:registry: 'https://npm.coremedia.io'
jobs:
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 20
if: github.actor != 'coremedia-ci' && github.actor != 'github-action[bot]'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Manual workflow trigger precondition check
if: github.event_name == 'workflow_dispatch' && (github.ref != 'refs/heads/main' || startsWith(github.ref, 'maintenance/'))
run: |
echo "::error Building a release is only allowed from main- or maintenance- branches!"
exit 1
#Make sure the release type is one of the allowed inputs.
- name: Workflow Dispatch release type check
if: github.event_name == 'workflow_dispatch' && !(github.event.inputs.release_type == 'major' || github.event.inputs.release_type == 'minor' || github.event.inputs.release_type == 'patch')
run: |
echo "Expected a release type due to the manual build execution on main branch."
echo "Allowed release types are: major, minor, patch"
exit 1
- name: Maintenance release type check
if: github.event_name == 'workflow_dispatch' && startsWith(github.ref, 'maintenance/') && !(github.event.inputs.release_type == 'patch')
run: |
echo "For maintenance branches only patch versions are allowed."
exit 1
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Configure NPM
run: |
NPM_AUTH_TOKEN=$(curl -s -H "Accept: application/json" -H "Content-Type:application/json" -X PUT --data '{"name": "${{ secrets.CM_NPM_USER }}", "password": "${{ secrets.CM_NPM_PASSWORD }}"}' https://npm.coremedia.io/-/user/org.couchdb.user:${{ secrets.CM_NPM_USER }} | jq -r .token)
echo "::add-mask::$NPM_AUTH_TOKEN"
echo "NPM_AUTH_TOKEN=$NPM_AUTH_TOKEN" >> $GITHUB_ENV
echo "NPM_CONFIG_//npm.coremedia.io/:_authToken=$NPM_AUTH_TOKEN" >> $GITHUB_ENV
npm install -g pnpm@${{ env.PNPM_VERSION }}
- name: Setup Git
run: |
git config --global user.name 'coremedia-ci'
git config --global user.email '[email protected]'
git pull
- name: Install
run: pnpm install
- name: "Validate peerDependencies"
run: pnpm script:validate-peers
# BY MANUAL TRIGGER ONLY!
# Set the release version to actual MAJOR.MINOR.PATCH version.
# If a prerelease is triggered manually, we keep the prerelease version for this workflow.
- name: Create Release Version
if: github.event_name == 'workflow_dispatch'
run: |
if [ -n "$(git status --porcelain)" ]; then
git status
echo "error:: There are unexpected changes in git!";
exit 1
fi
# Also updates .release-version
next_version=$(pnpm --silent "script:version" --release ${{ github.event.inputs.release_type }} --write)
echo "Next version: ${next_version}"
pnpm run setversion ${next_version} --filter=coremedia/* --dependencyVersion=^${next_version}
git commit -am "ci: Set next release version to: ${next_version}"
pnpm install --no-frozen-lockfile
git commit -am "ci: Update pnpm-lock.yaml for version ${next_version}"
# Set prerelease version.
# On push, we only want to provide a possible rc, which is testable and maybe already testable by our customers.
# Make sure to set the dependency versions to the concrete version as prerelease versions are not referenced by semver ranges.
- name: Create Prerelease Version
if: github.event_name == 'push'
# Make sure to not commit anything, which has been changed in one of the previous steps.
# Update the version, afterwards commit and push.
run: |
if [ -n "$(git status --porcelain)" ]; then
git status
echo "error:: There are unexpected changes in git!";
exit 1
fi
# Also updates .release-version
next_version=$(pnpm --silent "script:version" --release-candidate --write)
echo "Next version: ${next_version}"
pnpm run setversion ${next_version} --filter=coremedia/* --dependencyVersion=${next_version}
git commit -am "Set next release-candidate version to: ${next_version}"
pnpm install --no-frozen-lockfile
git commit -am "ci: Update pnpm-lock.yaml for version ${next_version}"
- name: Build
run: |
pnpm build
- name: Lint
run: pnpm lint
- name: Test
run: pnpm jest
- name: Playwright Tests
run: pnpm playwright
- name: TypeDoc
run: |
if [ -n "$(git status --porcelain)" ]; then
git status
echo "error:: There are unexpected changes in git!";
exit 1
fi
pnpm doc
git add --all
git commit -am "doc(typedoc): Update typedoc"
- name: Install for Production
run: pnpm install --production
# Publishes a release candidate with tag "next".
- name: Publish RC
if: github.event_name == 'push'
run: |
echo '//npm.coremedia.io/:_authToken=${NPM_AUTH_TOKEN}' > .npmrc
pnpm publishall --registry=https://npm.coremedia.io --no-git-checks --tag next
git reset --hard
# Publishes a release with tag "latest"
- name: Publish Release
if: github.event_name == 'workflow_dispatch'
run: |
echo '//npm.coremedia.io/:_authToken=${NPM_AUTH_TOKEN}' > .npmrc
pnpm publishall --registry=https://npm.coremedia.io --no-git-checks
git reset --hard
- name: Push commits
run: git push
- name: Create git tag
if: github.event_name == 'workflow_dispatch'
run: |
git tag $(cat .release-version)
git push origin $(cat .release-version)