|
| 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 | + # 'registry-url' is required for 'npm publish' |
| 27 | + registry-url: 'https://registry.npmjs.org' |
| 28 | + |
| 29 | + - name: Install Dependencies |
| 30 | + run: npm ci --ignore-scripts |
| 31 | + |
| 32 | + - name: Build NPM package |
| 33 | + run: npm run build:npm |
| 34 | + |
| 35 | + - name: Modify NPM package to be canary release |
| 36 | + uses: actions/github-script@v5 |
| 37 | + with: |
| 38 | + script: | |
| 39 | + const assert = require('assert'); |
| 40 | + const { readFileSync, writeFileSync } = require('fs'); |
| 41 | + const packageJSONPath = './npmDist/package.json'; |
| 42 | +
|
| 43 | + const packageJSON = JSON.parse(readFileSync(packageJSONPath, 'utf-8')); |
| 44 | +
|
| 45 | + let { version } = packageJSON; |
| 46 | + assert(!version.includes('+'), 'Can not append after metadata'); |
| 47 | + version += packageJSON.version.includes('-') ? '.' : '-'; |
| 48 | + version += `canary.pr.${context.issue.number}.${context.sha}`; |
| 49 | +
|
| 50 | + packageJSON.version = version; |
| 51 | + packageJSON.publishConfig.tag = 'canary-pr'; |
| 52 | + writeFileSync(packageJSONPath, JSON.stringify(packageJSON, null, 2), 'utf-8'); |
| 53 | +
|
| 54 | + core.exportVariable('NPM_VERSION', version); |
| 55 | +
|
| 56 | + - name: Publish NPM package |
| 57 | + run: npm publish ./npmDist |
| 58 | + env: |
| 59 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 60 | + |
| 61 | + - name: Add deprecate message on NPM package |
| 62 | + run: | |
| 63 | + npm deprecate "graphql@$NPM_VERSION" \ |
| 64 | + "You are using canary version build from ${{github.event.pull_request.url}}" |
| 65 | + env: |
| 66 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 67 | + |
| 68 | + - name: Add deprecate message on NPM package |
| 69 | + uses: actions/github-script@v5 |
| 70 | + with: |
| 71 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 72 | + script: | |
| 73 | + github.rest.issues.createComment({ |
| 74 | + issue_number: context.issue.number, |
| 75 | + owner: context.repo.owner, |
| 76 | + repo: context.repo.repo, |
| 77 | + body: |
| 78 | + `The latest changes of this PR are available as 'graphql@${process.env.NPM_VERSION}' on NPM.`, |
| 79 | + }) |
0 commit comments