253 lines
7 KiB
YAML
253 lines
7 KiB
YAML
name: Comment on the pull request
|
|
|
|
# read-write repo token
|
|
# access to secrets
|
|
on:
|
|
workflow_run:
|
|
workflows: ["Receive PR"]
|
|
types:
|
|
- completed
|
|
env:
|
|
YAO_DEV: ${{ github.WORKSPACE }}
|
|
YAO_ENV: development
|
|
YAO_ROOT: ${{ github.WORKSPACE }}/tests
|
|
YAO_HOST: 0.0.0.0
|
|
YAO_PORT: 5099
|
|
YAO_SESSION: "memory"
|
|
YAO_LOG: "./logs/application.log"
|
|
YAO_LOG_MODE: "TEXT"
|
|
YAO_JWT_SECRET: "bLp@bi!oqo-2U+hoTRUG"
|
|
YAO_DB_AESKEY: "ZLX=T&f6refeCh-ro*r@"
|
|
OSS_TEST_ID: ${{ secrets.OSS_TEST_ID}}
|
|
OSS_TEST_SECRET: ${{ secrets.OSS_TEST_SECRET}}
|
|
ROOT_PLUGIN: ${{ github.WORKSPACE }}/../../../data/gou-unit/plugins
|
|
|
|
MYSQL_TEST_HOST: "127.0.0.1"
|
|
MYSQL_TEST_PORT: "3308"
|
|
MYSQL_TEST_USER: test
|
|
MYSQL_TEST_PASS: "123456"
|
|
|
|
SQLITE_DB: "./app/db/yao.db"
|
|
|
|
REDIS_TEST_HOST: "127.0.0.1"
|
|
REDIS_TEST_PORT: "6379"
|
|
REDIS_TEST_DB: "2"
|
|
|
|
MONGO_TEST_HOST: "127.0.0.1"
|
|
MONGO_TEST_PORT: "27017"
|
|
MONGO_TEST_USER: "root"
|
|
MONGO_TEST_PASS: "123456"
|
|
|
|
DEMO_APP: ${{ github.WORKSPACE }}/../app
|
|
|
|
jobs:
|
|
UnitTest:
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
go: [1.18.2]
|
|
db: [MySQL8.0, MySQL5.7, SQLite3]
|
|
redis: [4, 5, 6]
|
|
mongo: ["6.0"]
|
|
if: >
|
|
${{ github.event.workflow_run.event == 'pull_request' &&
|
|
github.event.workflow_run.conclusion == 'success' }}
|
|
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 ${{ matrix.db }} test workflow is running, the results of the run will be commented later.'
|
|
});
|
|
|
|
- name: Setup Cache
|
|
uses: actions/cache@v2
|
|
with:
|
|
path: |
|
|
~/.cache/go-build
|
|
~/go/pkg/mod
|
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-go-
|
|
|
|
- name: Checkout Kun
|
|
uses: actions/checkout@v2
|
|
with:
|
|
repository: yaoapp/kun
|
|
path: kun
|
|
|
|
- name: Checkout Xun
|
|
uses: actions/checkout@v2
|
|
with:
|
|
repository: yaoapp/xun
|
|
path: xun
|
|
|
|
- name: Checkout Gou
|
|
uses: actions/checkout@v2
|
|
with:
|
|
repository: yaoapp/gou
|
|
path: gou
|
|
|
|
- name: Checkout V8Go
|
|
uses: actions/checkout@v2
|
|
with:
|
|
repository: rogchap/v8go
|
|
ref: 5e91d3d9dcabd2986f901b6b31590e49fc3c4dd8
|
|
path: v8go
|
|
|
|
- name: Checkout Demo App
|
|
uses: actions/checkout@v2
|
|
with:
|
|
repository: yaoapp/demo-app
|
|
path: app
|
|
|
|
- name: Move Kun, Xun, Gou, V8Go
|
|
run: |
|
|
mv kun ../
|
|
mv xun ../
|
|
mv gou ../
|
|
mv v8go ../
|
|
mv app ../
|
|
ls -l .
|
|
ls -l ../
|
|
|
|
- name: Checkout pull request HEAD commit
|
|
uses: actions/checkout@v2
|
|
with:
|
|
ref: ${{ env.HEAD }}
|
|
|
|
- name: Start Redis
|
|
uses: supercharge/redis-github-action@1.4.0
|
|
with:
|
|
redis-version: ${{ matrix.redis }}
|
|
|
|
- name: Start MongoDB
|
|
uses: supercharge/mongodb-github-action@1.8.0
|
|
with:
|
|
mongodb-version: ${{ matrix.mongo }}
|
|
mongodb-username: root
|
|
mongodb-password: 123456
|
|
mongodb-db: test
|
|
|
|
- name: Setup MySQL8.0 (connector)
|
|
uses: ./.github/actions/setup-db
|
|
with:
|
|
kind: "MySQL8.0"
|
|
db: "test"
|
|
user: "test"
|
|
password: "123456"
|
|
port: "3308"
|
|
|
|
- name: Setup ${{ matrix.db }}
|
|
uses: ./.github/actions/setup-db
|
|
with:
|
|
kind: "${{ matrix.db }}"
|
|
db: "xiang"
|
|
user: "xiang"
|
|
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 & Host
|
|
env:
|
|
PASSWORD: ${{ secrets.UNIT_PASS }}
|
|
run: |
|
|
sudo echo "127.0.0.1 local.iqka.com" | sudo tee -a /etc/hosts
|
|
echo "YAO_DB_DRIVER=$DB_DRIVER" >> $GITHUB_ENV
|
|
echo "GITHUB_WORKSPACE:\n" && ls -l $GITHUB_WORKSPACE
|
|
|
|
if [ "$DB_DRIVER" = "mysql" ]; then
|
|
echo "YAO_DB_PRIMARY=$DB_USER:$PASSWORD@$DB_HOST" >> $GITHUB_ENV
|
|
elif [ "$DB_DRIVER" = "postgres" ]; then
|
|
echo "YAO_DB_PRIMARY=postgres://$DB_USER:$PASSWORD@$DB_HOST" >> $GITHUB_ENV
|
|
else
|
|
echo "YAO_DB_PRIMARY=$YAO_ROOT/$DB_HOST" >> $GITHUB_ENV
|
|
fi
|
|
|
|
echo ".:\n" && ls -l .
|
|
echo "..:\n" && ls -l ..
|
|
ping -c 1 -t 1 local.iqka.com
|
|
|
|
- name: Test Prepare
|
|
run: |
|
|
make vet
|
|
make fmt-check
|
|
make misspell-check
|
|
make plugin
|
|
mkdir -p $YAO_ROOT/plugins/
|
|
mv $ROOT_PLUGIN/user.so $YAO_ROOT/plugins/
|
|
ls -l $YAO_ROOT/plugins/
|
|
make migrate
|
|
|
|
- name: Run test
|
|
run: |
|
|
make test
|
|
|
|
- name: Run widgets test
|
|
run: |
|
|
echo "YAO_ROOT=$DEMO_APP" >> $GITHUB_ENV
|
|
make test-widgets
|
|
|
|
- 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✨ ${{ matrix.db }} passed.'
|
|
});
|