diff --git a/.github/workflows/canary.yaml b/.github/workflows/canary.yaml new file mode 100644 index 00000000000..924182cc651 --- /dev/null +++ b/.github/workflows/canary.yaml @@ -0,0 +1,77 @@ +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 }} + + - 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@v3 + 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.`, + })