Skip to content

Commit

Permalink
github-actions-bot: fix reply on commands (#3538)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored Apr 22, 2022
1 parent 0926554 commit 16503cd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 52 deletions.
32 changes: 14 additions & 18 deletions .github/workflows/cmd-publish-pr-on-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
33 changes: 12 additions & 21 deletions .github/workflows/cmd-run-benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,21 +32,17 @@ jobs:

- name: Run Benchmark
run: |
npm run benchmark -- --revs HEAD BASE | tee benchmark.log
cat <<EOF >> replyMessage.txt
<details>
<summary> Benchmark output </summary>
EOF
npm run benchmark -- --revs HEAD BASE | tee -a replyMessage.txt
cat <<EOF >> replyMessage.txt
</details>
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 = `
<details>
<summary> Benchmark output </summary>
${ fs.readFileSync('./benchmark.log', 'utf-8') }
</details>
`;
core.setOutput('replyMessage', replyMessage);
name: replyMessage
path: ./replyMessage.txt
38 changes: 25 additions & 13 deletions .github/workflows/github-actions-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand All @@ -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) }}

0 comments on commit 16503cd

Please sign in to comment.