Skip to content

Review and build

Review and build #2

name: Review and build
on:
workflow_run:
workflows:
- Trigger "Review and build" action
types:
- completed
jobs:
download_data:
name: Download event data
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
outputs:
event_data: ${{ steps.output_event_data.outputs.event_data }}
steps:
- name: Download artifact
uses: dawidd6/action-download-artifact@v3.1.4
with:
workflow: build_on_pull_request_trigger.yml
name: event_data
- name: Output event data
id: output_event_data
run: echo event_data=$(<./event_data.json) >> $GITHUB_OUTPUT
test:
name: Test
needs: download_data
uses: ./.github/workflows/test.yml
with:
ref: ${{ fromJSON(needs.download_data.outputs.event_data).pull_request.head.sha }}
continue_on_error: true
review:
name: Submit a review
needs:
- download_data
- test
runs-on: ubuntu-latest
permissions:
pull-requests: write
outputs:
review_data: ${{ steps.output_review.outputs.review_data }}
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
with:
ref: ${{ fromJSON(needs.download_data.outputs.event_data).pull_request.head.sha }}
- name: Setup Node.js
uses: actions/setup-node@v4.0.2
with:
node-version: 20.12.0
cache: npm
- name: Install dependencies
run: npm install
- name: Prepare output folder
run: mkdir ./out
- name: Get diff
run: gh pr diff ${{ fromJSON(needs.download_data.outputs.event_data).number }} --repo ${{ github.repository }} > ./out/diff.log
env:
GH_TOKEN: ${{ github.token }}
- name: Create review data
run: ../../node_modules/.bin/ts-node ./submit_review.ts ${{ fromJSON(needs.download_data.outputs.event_data).pull_request.head.sha }} '${{ needs.test.outputs.test_1 }}' '${{ needs.test.outputs.test_2 }}'
working-directory: ./src/tests/
- name: Output review data
id: output_review
run: echo review_data=$(<./out/review.json) >> $GITHUB_OUTPUT
- name: Submit review
run: |
curl -L \
-X POST \
-H 'Accept: application/vnd.github+json' \
-H 'Authorization: Bearer ${{ github.token }}' \
-H 'X-GitHub-Api-Version: 2022-11-28' \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ fromJSON(needs.download_data.outputs.event_data).number }}/reviews \
-d '${{ steps.output_review.outputs.review_data }}'
build:
name: Build
needs:
- download_data
- review
if: ${{ fromJSON(needs.review.outputs.review_data).event == 'COMMENT' }}
uses: ./.github/workflows/build.yml
with:
ref: ${{ fromJSON(needs.download_data.outputs.event_data).pull_request.head.sha }}
comment:
name: Send comment
needs:
- download_data
- build
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Create comment file
run: |
cat << EOF > ./comment.txt
Finished building translation data. You can get it from the following link:
https://github.com/Gakuto1112/Stormworks-JapaneseTranslation/actions/runs/${{ needs.build.outputs.run_id }}
EOF
- name: Send comment
run: gh pr comment ${{ fromJSON(needs.download_data.outputs.event_data).number }} --body-file ./comment.txt --repo ${{ github.repository }}
env:
GH_TOKEN: ${{ github.token }}
request_review:
name: Request a review for the pull request to Gakuto1112
needs:
- download_data
- review
if: ${{ fromJSON(needs.review.outputs.review_data).event == 'COMMENT' && fromJSON(needs.download_data.outputs.event_data).pull_request.user.login != 'Gakuto1112' }}
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Check requested reviewers
id: check_reviewers
continue-on-error: true
run: |
gh api \
-H 'Accept: application/vnd.github+json' \
-H 'X-GitHub-Api-Version: 2022-11-28' \
/repos/${{ github.repository }}/pulls/${{ fromJSON(needs.download_data.outputs.event_data).number }}/requested_reviewers \
| jq .users[].login | grep Gakuto1112
env:
GH_TOKEN: ${{ github.token }}
- name: Check reviews
id: check_reviews
continue-on-error: true
run: |
gh api \
-H 'Accept: application/vnd.github+json' \
-H 'X-GitHub-Api-Version: 2022-11-28' \
/repos/${{ github.repository }}/pulls/${{ fromJSON(needs.download_data.outputs.event_data).number }}/reviews \
| jq .[].user.login | grep Gakuto1112
env:
GH_TOKEN: ${{ github.token }}
- name: Request a review for the pull request to Gakuto1112
if: ${{ steps.check_reviewers.outcome == 'failure' && steps.check_reviews.outcome == 'failure' }}
run: |
gh api \
--method POST \
-H 'Accept: application/vnd.github+json' \
-H 'X-GitHub-Api-Version: 2022-11-28' \
/repos/${{ github.repository }}/pulls/${{ fromJSON(needs.download_data.outputs.event_data).number }}/requested_reviewers \
-f 'reviewers[]=Gakuto1112'
env:
GH_TOKEN: ${{ github.token }}