Skip to content

Commit 77005ee

Browse files
committed
ci: add canary releases on PRs
Fixes graphql#3466 Fixes graphql#3383
1 parent f597c69 commit 77005ee

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

.github/workflows/canary.yaml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Canary Release
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
env:
9+
NODE_VERSION_USED_FOR_DEVELOPMENT: 17
10+
jobs:
11+
publish-canary:
12+
name: Publish Canary
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Main
16+
uses: actions/checkout@v2
17+
with:
18+
fetch-depth: 0
19+
persist-credentials: false
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v2
23+
with:
24+
cache: npm
25+
node-version: ${{ env.NODE_VERSION_USED_FOR_DEVELOPMENT }}
26+
27+
- name: Install Dependencies
28+
run: npm ci --ignore-scripts
29+
30+
- name: Build NPM package
31+
run: npm run build:npm
32+
33+
- name: Modify NPM package to be canary release
34+
uses: actions/github-script@v5
35+
with:
36+
script: |
37+
const assert = require('assert');
38+
const { readFileSync, writeFileSync } = require('fs');
39+
const packageJSONPath = './npmDist/package.json';
40+
41+
const packageJSON = JSON.parse(readFileSync(packageJSONPath, 'utf-8'));
42+
43+
let { version } = packageJSON;
44+
assert(!version.includes('+'), 'Can not append after metadata');
45+
version += packageJSON.version.includes('-') ? '.' : '-';
46+
version += `canary.pr.${context.issue.number}.${context.sha}`;
47+
48+
packageJSON.version = version;
49+
packageJSON.publishConfig.tag = 'canary-pr';
50+
writeFileSync(packageJSONPath, JSON.stringify(packageJSON, null, 2), 'utf-8');
51+
52+
core.exportVariable('NPM_VERSION', version);
53+
54+
- name: Publish NPM package
55+
run: npm publish ./npmDist
56+
env:
57+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
58+
59+
- name: Add deprecate message on NPM package
60+
run: |
61+
npm deprecate "graphql@$NPM_VERSION" \
62+
"You are using canary version build from ${{github.event.pull_request.url}}"
63+
env:
64+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
65+
66+
- name: Add deprecate message on NPM package
67+
uses: actions/github-script@v3
68+
with:
69+
github-token: ${{secrets.GITHUB_TOKEN}}
70+
script: |
71+
github.rest.issues.createComment({
72+
issue_number: context.issue.number,
73+
owner: context.repo.owner,
74+
repo: context.repo.repo,
75+
body:
76+
`The latest changes of this PR are available as 'graphql@${process.env.NPM_VERSION}' on NPM.`,
77+
})

0 commit comments

Comments
 (0)