generated from iadvize/hello-world-monorepo-javascript-library
-
Notifications
You must be signed in to change notification settings - Fork 1
136 lines (111 loc) · 4.09 KB
/
canary.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
name: Canary deployment
on:
pull_request:
types: [labeled, synchronize]
paths:
- 'packages/**/*'
jobs:
publish-canary:
name: 'publish canary'
runs-on: ubuntu-latest
if: contains(join(github.event.pull_request.labels.*.name), 'packages/')
steps:
- uses: actions/checkout@v2-beta
- name: Extract package name
id: name
uses: actions/github-script@0.4.0
with:
github-token: ${{ secrets.GITHUB_TOKEN_REPO_WRITE }}
previews: 'ant-man-preview,flash-preview'
script: |
const { data: pullLabels } = await github.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
per_page: 100,
});
const labels = pullLabels.map(label => label.name);
const packageLabels = labels.filter(name => name.includes('packages/'));
console.log(`::debug ::${packageLabels.length} matching labels`);
if (packageLabels.length > 1) {
throw new Error('Pull request should have only one package label');
}
if (packageLabels.length === 1) {
console.log(`::set-output name=package::${packageLabels[0]}`)
return;
}
throw new Error('Pull request is not labeled with packages, should not be here');
- name: Compute canary version
id: compute-version
env:
# TODO - concat check-suite run id when added by Github to prevent
# conflict when re-running workflow on the same commit
PACKAGE: ${{ steps.name.outputs.package }}
run: |
cd $PACKAGE
COMMIT=$(git rev-parse --short HEAD)
NOW=$(date +%s%3N)
CURRENT_VERSION=$(cat package.json | jq -r '.version')
NEW_VERSION=$CURRENT_VERSION-canary-$COMMIT-$NOW
NAME=$(cat package.json | jq -r '.name')
echo "::set-output name=version::$NEW_VERSION"
echo "::set-output name=name::$NAME"
- uses: actions/setup-node@v3
with:
registry-url: https://registry.npmjs.org/
node-version: '16'
- name: Cache npm cache
uses: actions/cache@v1
with:
path: ~/.npm
key: v1-npm-${{ github.event.pull_request.head.ref }}-${{ hashFiles(format('{0}/package-lock.json', steps.name.outputs.package)) }}
restore-keys: |
v1-npm-${{ github.event.pull_request.head.ref }}-
v1-npm-
- name: Install
if: steps.node-modules-cache.outputs.cache-hit != 'true'
env:
PACKAGE: ${{ steps.name.outputs.package }}
run: |
cd $PACKAGE
npm ci
- name: Bumb version
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
VERSION: ${{ steps.compute-version.outputs.version }}
PACKAGE: ${{ steps.name.outputs.package }}
run: |
cd $PACKAGE
npm version --no-git-tag-version $VERSION
- name: Create deployment
id: deployment
uses: actions/github-script@0.4.0
env:
NAME: ${{ steps.compute-version.outputs.name }}
VERSION: ${{ steps.compute-version.outputs.version }}
DIRECTORY: ${{ steps.name.outputs.package }}
with:
github-token: ${{ secrets.GITHUB_TOKEN_REPO_WRITE }}
previews: 'ant-man-preview,flash-preview'
script: |
const name = process.env.NAME;
const version = process.env.VERSION;
const directory = process.env.DIRECTORY;
const branch = context.payload.pull_request.head.ref;
const { data: deployment } = await github.repos.createDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
ref: branch,
environment: 'npm',
auto_merge: false,
required_contexts: [],
payload: {
version,
name,
directory,
ref: context.payload.pull_request.head.sha,
npmTag: branch,
},
description: `Deploy ${name}@${version} on npm`,
production_environment: true,
});