generated from int128/typescript-actions-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 1
139 lines (114 loc) · 3.89 KB
/
ci.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
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
concurrency: ${{ github.ref }}-ci
jobs:
ci:
outputs:
shouldCancel: ${{ steps.batchRuns.outputs.shouldCancel }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: yarn
- run: yarn --frozen-lockfile --ignore-scripts
- run: yarn syncpack:check
- run: yarn format:check
- run: yarn beachball check
- run: yarn build
- run: yarn lint
- run: yarn test
- run: yarn package
- name: e2e - install-beachball
uses: ./install-beachball
- name: e2e - check-for-modified-files
uses: ./check-for-modified-files
- name: e2e - batch-runs
uses: ./batch-runs
id: batchRuns
with:
mode: output
token: ${{ github.token }}
- name: e2e - batch-runs result
uses: actions/github-script@v7
if: ${{ steps.batchRuns.outputs.shouldCancel != 'no' }}
with:
script: |
const shouldCancel = '${{ steps.batchRuns.outputs.shouldCancel }}';
if (shouldCancel === 'yes' && process.env.GITHUB_REF_NAME === 'main') {
core.info('Newer run is pending for main');
} else {
core.setFailed(`batch-runs unexpectedly returned "${shouldCancel}"`);
}
# Note: this is not actually used here to determine if a release is needed
- name: e2e - should-release
uses: ./should-release
id: shouldRelease
with:
mode: output
token: ${{ github.token }}
batch: true
- name: e2e - should-release result
uses: actions/github-script@v7
with:
script: |
const shouldRelease = '${{ steps.shouldRelease.outputs.shouldRelease }}';
if (shouldRelease !== 'yes' && shouldRelease !== 'no') {
core.setFailed(`should-release returned "${shouldRelease}" instead of "yes" or "no"`);
} else {
core.info(`should-release returned shouldRelease: "${shouldRelease}"`);
}
# Run the release in a separate job with release environment access.
# This approach requires re-running the build but skips the tests.
release:
needs: ci
if: ${{ github.ref == 'refs/heads/main' && needs.ci.outputs.shouldCancel == 'no' }}
runs-on: ubuntu-latest
# This environment contains secrets needed for releasing
environment: release
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: yarn
- run: yarn --frozen-lockfile --ignore-scripts
- run: yarn build
- run: yarn package
# Verify that no newer runs were queued since the check in the previous job
- uses: ./batch-runs
id: batchRuns
with:
mode: output
token: ${{ github.token }}
- name: Set git config
run: |
git config user.name "Elizabeth Craig"
git config user.email "[email protected]"
git remote set-url origin "https://[email protected]/$GITHUB_REPOSITORY"
env:
REPO_PAT: ${{ secrets.REPO_PAT }}
- name: Publish common package to npm
if: ${{ steps.batchRuns.outputs.shouldCancel == 'no' }}
run: |
yarn beachball publish -b origin/main -y -n "$NPM_TOKEN"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Release actions
if: ${{ steps.batchRuns.outputs.shouldCancel == 'no' }}
uses: int128/release-typescript-action@v1
with:
major-version: 2
token: ${{ github.token }}