-
Notifications
You must be signed in to change notification settings - Fork 27
149 lines (126 loc) · 5.58 KB
/
publish.yaml
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
name: Publish to NPM
on:
workflow_dispatch:
inputs:
release_type:
type: choice
description: Release Type
options:
- alpha
- release
required: true
default: alpha
upgrade_type:
type: choice
description: Upgrade Type
options:
- none
- patch
- minor
# - major
required: false
default: none
dry_run:
type: boolean
description: "(Optional) Dry run"
required: false
default: false
jobs:
Publish:
name: Publish Workflow
runs-on: ubuntu-latest-4-cores
env:
GH_TOKEN: ${{ secrets.PLATFORM_SA_GITHUB_TOKEN }}
NODE_OPTIONS: --max-old-space-size=14366
SDK_PUBLISH_SLACK_WEBHOOK: ${{ secrets.SDK_PUBLISH_SLACK_WEBHOOK }}
steps:
- name: Check Public Release Branch
if: contains(github.event.inputs.release_type, 'release') && (github.ref != 'refs/heads/main')
run: failure("Public releases should be only done from main branch, current branch ${{ github.ref }}")
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Github
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Get tags
run: git fetch --tags
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: lts/*
cache: 'yarn'
- name: Workout next version string
run: |
upgrade_type=${{ github.event.inputs.upgrade_type }}
if [ ${{ contains(github.event.inputs.upgrade_type, 'none') }} == true ]
then
upgrade_type=""
revision_upgrade=$( ${{ contains(github.event.inputs.release_type, 'alpha') }} && echo '--revision' || echo '')
echo $revision
fi
./.github/scripts/version-up.sh --${{ github.event.inputs.release_type }} --$upgrade_type --apply $revision_upgrade
shell: bash
- name: Install dependencies
run: yarn install --immutable
- name: Lint
run: yarn lint
- name: Check Single Package Version Policy
run: yarn syncpack:check
- name: Get next version string
id: version
run: |
echo "NEXT_VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT
- name: Update package.json version for build
run: |
tmp=$(mktemp)
jq '.version = "${{steps.version.outputs.NEXT_VERSION}}"' ./sdk/package.json > "$tmp" && mv "$tmp" ./sdk/package.json
- name: Build
run: export NODE_OPTIONS=--max-old-space-size=6144 && RELEASE_TYPE=${{ github.event.inputs.release_type }} yarn build
- name: Typecheck
run: yarn typecheck
- name: Test
run: yarn test
- name: Push tags
# Boolean inputs are not actually booleans, see https://github.com/actions/runner/issues/1483
if: github.event.inputs.dry_run == 'false'
run: |
echo "$(git push --tags)"
- name: Pre Release Step
if: contains(github.event.inputs.release_type, 'alpha')
id: pre_release
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.PLATFORM_SA_NPM_TOKEN }}
access: public
package: ./sdk/package.json
tag: ${{ contains(github.event.inputs.release_type, 'alpha') && 'alpha' }}
dry-run: ${{ github.event.inputs.dry_run }}
- name: Authenticate NPM
if: contains(github.event.inputs.release_type, 'release')
run: npm config set //registry.npmjs.org/:_authToken ${{ secrets.PLATFORM_SA_NPM_TOKEN }}
- name: Release
id: npm_release
if: contains(github.event.inputs.release_type, 'release')
run: yarn release --ci --no-increment -c .release-it.json $( ${{ github.event.inputs.dry_run }} && echo "--dry-run" || echo "") --github.tokenRef=${{ secrets.RELEASE_TOKEN }}
- name: Create GitHub Release
if: contains(github.event.inputs.release_type, 'release') && github.event.inputs.dry_run == 'false'
run: gh release create ${{ steps.version.outputs.NEXT_VERSION }} --title ${{ steps.version.outputs.NEXT_VERSION }} --draft=false --prerelease=false --generate-notes --repo immutable/ts-immutable-sdk
- name: Get GitHub Release Name and URL
if: contains(github.event.inputs.release_type, 'release') && github.event.inputs.dry_run == 'false'
id: release
run: |
echo "RELEASE_NAME=$(gh release view --json name | jq -r .name)" >> $GITHUB_OUTPUT
echo "RELEASE_URL=$(gh release view --json url | jq -r .url)" >> $GITHUB_OUTPUT
- name: Notify SDK Slack Publish Success
if: ${{ success() && (steps.npm_release.conclusion == 'success' || steps.pre_release.conclusion == 'success') && github.event.inputs.dry_run == 'false' }}
uses: ./.github/actions/notify-slack-publish-status
with:
message: "✅ Successfully published SDK version ${{steps.version.outputs.NEXT_VERSION}} to NPM.\n\nhttps://www.npmjs.com/package/@imtbl/sdk/v/${{steps.version.outputs.NEXT_VERSION}}"
- name: Notify SDK Slack Publish Failure
if: ${{ failure() && (steps.npm_release.conclusion == 'failure' || steps.pre_release.conclusion == 'failure') && github.event.inputs.dry_run == 'false' }}
uses: ./.github/actions/notify-slack-publish-status
with:
message: "❌ Failed to publish SDK version ${{steps.version.outputs.NEXT_VERSION}} to NPM. Please check the logs for more details."