From 16503cd1927da5f2928d4abfa84a64b3502bd6ba Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Fri, 22 Apr 2022 15:47:19 +0300 Subject: [PATCH] github-actions-bot: fix reply on commands (#3538) --- .github/workflows/cmd-publish-pr-on-npm.yml | 32 ++++++++--------- .github/workflows/cmd-run-benchmark.yml | 33 +++++++----------- .github/workflows/github-actions-bot.yml | 38 ++++++++++++++------- 3 files changed, 51 insertions(+), 52 deletions(-) diff --git a/.github/workflows/cmd-publish-pr-on-npm.yml b/.github/workflows/cmd-publish-pr-on-npm.yml index f3149593a7..98f6f5dcc1 100644 --- a/.github/workflows/cmd-publish-pr-on-npm.yml +++ b/.github/workflows/cmd-publish-pr-on-npm.yml @@ -8,9 +8,6 @@ on: secrets: NPM_CANARY_PR_PUBLISH_TOKEN: required: true - outputs: - replyMessage: - value: ${{ jobs.publish-canary.outputs.replyMessage }} jobs: build-npm-dist: runs-on: ubuntu-latest @@ -43,8 +40,6 @@ jobs: runs-on: ubuntu-latest name: Publish Canary environment: canary-pr-npm - outputs: - replyMessage: ${{ steps.set_replyMessage.outputs.replyMessage }} needs: [build-npm-dist] steps: - name: Checkout repo @@ -99,22 +94,23 @@ jobs: 'utf-8', ); - core.exportVariable('NPM_TAG', packageJSON.publishConfig.tag); - core.exportVariable('NPM_VERSION', packageJSON.version); + const replyMessage = ` + The latest changes of this PR are available on NPM as + [graphql@${packageJSON.version}](https://www.npmjs.com/package/graphql/v/${packageJSON.version}) + **Note: no gurantees provided so please use your own discretion.** + + Also you can depend on latest version built from this PR: + \`npm install --save graphql@${packageJSON.publishConfig.tag}\` + `; + fs.writeFileSync('./replyMessage.txt', replyMessage.trim(), 'utf-8'); - name: Publish NPM package run: npm publish --ignore-scripts ./npmDist env: NODE_AUTH_TOKEN: ${{ secrets.NPM_CANARY_PR_PUBLISH_TOKEN }} - - name: Set 'replyMessage' output variable - id: set_replyMessage - run: echo "::set-output replyMessage=$REPLY_MESSAGE" - env: - REPLY_MESSAGE: | - The latest changes of this PR are available on NPM as - [graphql@${{env.NPM_VERSION}}](https://www.npmjs.com/package/graphql/v/${{env.NPM_VERSION}}) - **Note: no gurantees provided so please use your own discretion.** - - Also you can depend on latest version built from this PR: - `npm install --save graphql@${{env.NPM_TAG}}` + - name: Upload replyMessage + uses: actions/upload-artifact@v2 + with: + name: replyMessage + path: ./replyMessage.txt diff --git a/.github/workflows/cmd-run-benchmark.yml b/.github/workflows/cmd-run-benchmark.yml index 2064d5b5be..7a9469e5a6 100644 --- a/.github/workflows/cmd-run-benchmark.yml +++ b/.github/workflows/cmd-run-benchmark.yml @@ -5,14 +5,9 @@ on: pullRequestJSON: required: true type: string - outputs: - replyMessage: - value: ${{ jobs.benchmark.outputs.replyMessage }} jobs: benchmark: name: Run benchmark - outputs: - replyMessage: ${{ steps.set_replyMessage.outputs.replyMessage }} runs-on: ubuntu-latest steps: - name: Checkout repo @@ -37,21 +32,17 @@ jobs: - name: Run Benchmark run: | - npm run benchmark -- --revs HEAD BASE | tee benchmark.log + cat <> replyMessage.txt +
+ Benchmark output + EOF + npm run benchmark -- --revs HEAD BASE | tee -a replyMessage.txt + cat <> replyMessage.txt +
+ EOF - - name: Set 'replyMessage' output variable - id: set_replyMessage - uses: actions/github-script@v5 + - name: Upload replyMessage + uses: actions/upload-artifact@v2 with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - const fs = require('fs'); - - const replyMessage = ` -
- Benchmark output - - ${ fs.readFileSync('./benchmark.log', 'utf-8') } -
- `; - core.setOutput('replyMessage', replyMessage); + name: replyMessage + path: ./replyMessage.txt diff --git a/.github/workflows/github-actions-bot.yml b/.github/workflows/github-actions-bot.yml index 8427bd072d..6d130a1296 100644 --- a/.github/workflows/github-actions-bot.yml +++ b/.github/workflows/github-actions-bot.yml @@ -56,7 +56,6 @@ jobs: runs-on: ubuntu-latest outputs: cmd: ${{ steps.parse-cmd.outputs.cmd }} - replyMessage: ${{ steps.parse-cmd.outputs.replyMessage }} pullRequestJSON: ${{ steps.parse-cmd.outputs.pullRequestJSON }} steps: - uses: actions/github-script@v5 @@ -103,26 +102,42 @@ jobs: if: needs.accept-cmd.result != 'skipped' && always() runs-on: ubuntu-latest steps: - - uses: actions/github-script@v5 + - uses: actions/download-artifact@v2 + with: + name: replyMessage + + - if: failure() + uses: actions/github-script@v5 with: script: | - const { issue, comment, sender } = context.payload; + const fs = require('fs'); + const needs = JSON.parse(process.env.NEEDS); - let replyMessage; let allSkipped = true; for (const [ name, job ] of Object.entries(needs)) { if (name.startsWith('cmd-')) { allSkipped = allSkipped && job.result === 'skipped'; } - replyMessage = replyMessage || job.outputs.replyMessage; } - if (!replyMessage) { - replyMessage = allSkipped - ? 'Unknown command 😕\n\n' + process.env.SUPPORTED_COMMANDS - : `Something went wrong, [please check log](${process.env.RUN_URL}).`; - } + const replyMessage = allSkipped + ? 'Unknown command 😕\n\n' + process.env.SUPPORTED_COMMANDS + : `Something went wrong, [please check log](${process.env.RUN_URL}).`; + + fs.writeFileSync('./replyMessage.txt', replyMessage, 'utf-8'); + env: + NEEDS: ${{ toJSON(needs) }} + RUN_URL: ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}} + + - if: always() + uses: actions/github-script@v5 + with: + script: | + const fs = require('fs'); + + const replyMessage = fs.readFileSync('./replyMessage.txt', 'utf-8'); + const { issue, comment, sender } = context.payload; const quoteRequest = comment.body .split('\n') @@ -142,6 +157,3 @@ jobs: { __typename } } `, { subjectId: comment.node_id }); - env: - RUN_URL: ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}} - NEEDS: ${{ toJSON(needs) }}