generated from iadvize/hello-world-javascript-library
-
Notifications
You must be signed in to change notification settings - Fork 1
86 lines (72 loc) · 2.42 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
name: Canary deployment
on:
pull_request:
types: [opened, synchronize]
jobs:
publish-canary:
name: 'publish canary'
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2-beta
- name: Compute canary version
id: compute-version
env:
ID: ${{ github.sha }}
run: |
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@v1
with:
registry-url: https://registry.npmjs.org/
node-verion: '12.x'
- name: Cache npm cache
uses: actions/cache@v1
with:
path: ~/.npm
key: v1-npm-${{ github.event.pull_request.head.ref }}-${{ hashFiles('package-lock.json') }}
restore-keys: |
v1-npm-${{ github.event.pull_request.head.ref }}-
v1-npm-
- name: Install
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: npm ci
- name: Bumb version
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
VERSION: ${{ steps.compute-version.outputs.version }}
run: |
npm version --no-git-tag-version $VERSION
- name: Create deployment
id: deployment
uses: actions/[email protected]
env:
NAME: ${{ steps.compute-version.outputs.name }}
VERSION: ${{ steps.compute-version.outputs.version }}
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 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,
ref: context.payload.pull_request.head.sha,
npmTag: branch,
},
description: `Deploy ${name}@${version} on npm`,
production_environment: true,
});