-
Notifications
You must be signed in to change notification settings - Fork 1
118 lines (117 loc) · 5.19 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
name: Releases
on:
push:
branches: [ main ]
workflow_dispatch:
inputs:
release_type:
description: 'Release type. Allowed values: "major", "minor", "patch"'
required: true
default: 'patch'
jobs:
build:
name: Build
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
NPM_CONFIG_@coremedia:registry: 'https://npm.coremedia.io'
NPM_CONFIG_//npm.coremedia.io/:_authToken: ${NPM_AUTH_TOKEN}
runs-on: ubuntu-latest
if: github.actor != 'coremedia-ci' && github.actor != 'github-action[bot]'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Manual workflow trigger precondition check
if: github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/main'
run: |
echo "::error Building a release is only allowed from main-branch!"
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.ref == 'refs/heads/main' && !(github.event.inputs.release_type == 'major' || github.event.inputs.release_type == 'minor' || github.event.inputs.release_type == 'patch' || github.event.inputs.release_type == 'prerelease')
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: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: Configure NPM
run: |
npm install -g pnpm@6.14.6
npm install -g semver
- name: Setup Git
run: |
git config --global user.name 'coremedia-ci'
git config --global user.email 'coremedia-ci@coremedia.com'
- name: Install
run: pnpm install
# ON MAIN 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' && github.ref == 'refs/heads/main'
run: |
if [ -n "$(git status --porcelain)" ]; then
git status
echo "error:: There are unexpected changes in git!";
exit 1
fi
actual_version=$(cat .release-version)
next_version=$(semver --increment ${{ github.event.inputs.release_type }} ${actual_version})
pnpm run setversion -- ${next_version} --filter=coremedia/* --dependencyVersion=^${next_version}
pnpm install --no-frozen-lockfile
echo "${next_version}" > .release-version
git commit -am "Set release version ${next_version}"
#Provide the actual version for later checks.
#Access: steps.read-version.outputs.version
- name: Read Version
id: read-version
run: |
release_version=$(cat .release-version)
echo "::set-output name=version::${release_version}"
#Require a prerelease version on main branch when not explicitly releasing.
#Guard to not accidentally release.
- name: Require Prerelease Version
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && !contains(steps.read-version.outputs.version, '-')
run: |
echo "Expected prerelease version on main"
exit 1
- name: Build
run: |
pnpm build
- name: Lint
run: pnpm lint
- name: Test
run: pnpm jest
- name: Install for Production
run: pnpm install --production
- name: Publish
if: github.ref == 'refs/heads/main'
run: |
echo '//npm.coremedia.io/:_authToken=${NPM_AUTH_TOKEN}' > .npmrc
pnpm publishall -- --registry=https://npm.coremedia.io
git reset --hard
# MAIN ONLY
# Set next prerelease version to prepare for next build.
# This ensures that we do not build one release number twice (for not getting conflicts in our repository)
- name: Create Next Prerelease Version
if: github.ref == 'refs/heads/main'
# 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
actual_version=$(cat .release-version)
next_version=$(semver --increment prerelease --preid rc ${actual_version})
pnpm run setversion -- ${next_version} --filter=coremedia/* --dependencyVersion=${next_version}
echo "${next_version}" > .release-version
pnpm install --no-frozen-lockfile
git commit -am "Set next prerelease version ${next_version}"
# Only push if something on main has been built. We don't want to have a lot of unnecessary version commits on every pull request.
- name: Push commits to git
if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
run: git push