Skip to content

Commit

Permalink
ci: add canary releases on PRs
Browse files Browse the repository at this point in the history
Fixes #3466
Fixes #3383
  • Loading branch information
IvanGoncharov committed Feb 1, 2022
1 parent f597c69 commit cbd154d
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/canary.yaml
@@ -0,0 +1,79 @@
name: Canary Release

on:
pull_request:
branches:
- main

env:
NODE_VERSION_USED_FOR_DEVELOPMENT: 17
jobs:
publish-canary:
name: Publish Canary
runs-on: ubuntu-latest
steps:
- name: Checkout Main
uses: actions/checkout@v2
with:
fetch-depth: 0
persist-credentials: false

- name: Setup Node.js
uses: actions/setup-node@v2
with:
cache: npm
node-version: ${{ env.NODE_VERSION_USED_FOR_DEVELOPMENT }}
# 'registry-url' is required for 'npm publish'
registry-url: 'https://registry.npmjs.org'

- name: Install Dependencies
run: npm ci --ignore-scripts

- name: Build NPM package
run: npm run build:npm

- name: Modify NPM package to be canary release
uses: actions/github-script@v5
with:
script: |
const assert = require('assert');
const { readFileSync, writeFileSync } = require('fs');
const packageJSONPath = './npmDist/package.json';
const packageJSON = JSON.parse(readFileSync(packageJSONPath, 'utf-8'));
let { version } = packageJSON;
assert(!version.includes('+'), 'Can not append after metadata');
version += packageJSON.version.includes('-') ? '.' : '-';
version += `canary.pr.${context.issue.number}.${context.sha}`;
packageJSON.version = version;
packageJSON.publishConfig.tag = 'canary-pr';
writeFileSync(packageJSONPath, JSON.stringify(packageJSON, null, 2), 'utf-8');
core.exportVariable('NPM_VERSION', version);
- name: Publish NPM package
run: npm publish ./npmDist
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Add deprecate message on NPM package
run: |
npm deprecate "graphql@$NPM_VERSION" \
"You are using canary version build from ${{github.event.pull_request.url}}"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Add deprecate message on NPM package
uses: actions/github-script@v5
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body:
`The latest changes of this PR are available as 'graphql@${process.env.NPM_VERSION}' on NPM.`,
})

0 comments on commit cbd154d

Please sign in to comment.