Comment on the pull request #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Comment on the pull request | ||
# read-write repo token | ||
# access to secrets | ||
on: | ||
workflow_run: | ||
workflows: ["Receive PR"] | ||
types: | ||
- completed | ||
jobs: | ||
unit-test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
matrix: | ||
go: [1.18.2] | ||
db: [MySQL8.0, MySQL5.7, MySQL5.6, Postgres9.6, Postgres14.0, SQLite3] | ||
steps: | ||
- name: "Download artifact" | ||
uses: actions/github-script@v3.1.0 | ||
with: | ||
script: | | ||
var artifacts = await github.actions.listWorkflowRunArtifacts({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
run_id: ${{github.event.workflow_run.id }}, | ||
}); | ||
var matchArtifact = artifacts.data.artifacts.filter((artifact) => { | ||
return artifact.name == "pr" | ||
})[0]; | ||
var download = await github.actions.downloadArtifact({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
artifact_id: matchArtifact.id, | ||
archive_format: 'zip', | ||
}); | ||
var fs = require('fs'); | ||
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); | ||
- name: "Read NR & SHA" | ||
run: | | ||
unzip pr.zip | ||
cat NR | ||
cat SHA | ||
echo HEAD=$(cat SHA) >> $GITHUB_ENV | ||
echo NR=$(cat NR) >> $GITHUB_ENV | ||
- name: "Comment on PR" | ||
uses: actions/github-script@v3 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const { NR } = process.env | ||
var fs = require('fs'); | ||
var issue_number = NR; | ||
await github.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issue_number, | ||
body: 'Thank you for the PR! The test workflow ( GO:${{ matrix.go }} DB:${{ matrix.db }} is running, the results of the run will be commented later.' | ||
}); | ||
- name: Setup ${{ matrix.db }} | ||
uses: ./.github/actions/setup-db | ||
with: | ||
kind: "${{ matrix.db }}" | ||
db: "xun" | ||
user: "xun" | ||
password: ${{ secrets.UNIT_PASS }} | ||
- name: Setup Go ${{ matrix.go }} | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go }} | ||
- name: Setup Go Tools | ||
run: | | ||
make tools | ||
- name: Setup ENV | ||
run: | | ||
echo "XUN_UNIT_NAME=$DB_NAME" >> $GITHUB_ENV | ||
echo "XUN_UNIT_DRIVER=$DB_DRIVER" >> $GITHUB_ENV | ||
echo "XUN_UNIT_LOG=$HOME/${{ matrix.db }}-${{ matrix.go }}.log" >> $GITHUB_ENV | ||
echo $PATH | ||
- name: Run Test | ||
env: | ||
PASSWORD: ${{ secrets.UNIT_PASS }} | ||
# POSTGRES_DSN: ${{ secrets.UNIT_POSTGRES_DSN }} | ||
run: | | ||
make vet | ||
make fmt-check | ||
make misspell-check | ||
if [ "$DB_DRIVER" = "mysql" ]; then | ||
XUN_UNIT_SOURCE="$DB_USER:$PASSWORD@$DB_HOST" make test | ||
elif [ "$DB_DRIVER" = "postgres" ]; then | ||
XUN_UNIT_SOURCE="postgres://$DB_USER:$PASSWORD@$DB_HOST" make test | ||
else | ||
XUN_UNIT_SOURCE="$DB_HOST" make test | ||
fi | ||
- name: Codecov Report | ||
uses: codecov/codecov-action@v2 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos | ||
- name: "Comment on PR" | ||
uses: actions/github-script@v3 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const { NR } = process.env | ||
var fs = require('fs'); | ||
var issue_number = NR; | ||
await github.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issue_number, | ||
body: '✨DONE✨ GO:${{ matrix.go }} DB:${{ matrix.db }} passed.' | ||
}); |