From 92dc4d16f1b4a392949f9e2c22e8f2bf6dfaf0c5 Mon Sep 17 00:00:00 2001 From: JongChan Choi Date: Fri, 16 Aug 2019 15:00:37 +0900 Subject: [PATCH] daily health check --- .github/workflows/push.yml | 2 +- .github/workflows/schedule.yml | 12 ++++++-- actions/deploy/Dockerfile | 7 ++--- actions/deploy/entrypoint.sh | 1 - actions/push-health-check/Dockerfile | 13 +++++++++ actions/push-health-check/entrypoint.sh | 38 +++++++++++++++++++++++++ src/test/health-check/index.ts | 5 +++- 7 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 actions/push-health-check/Dockerfile create mode 100644 actions/push-health-check/entrypoint.sh diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index ac401f4a..d4e1007d 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -1,5 +1,5 @@ -on: push name: Test and deploy +on: push jobs: install: name: Install diff --git a/.github/workflows/schedule.yml b/.github/workflows/schedule.yml index 5f0614da..f841edc3 100644 --- a/.github/workflows/schedule.yml +++ b/.github/workflows/schedule.yml @@ -1,18 +1,26 @@ +name: Run health check on: schedule: - cron: 0 0 * * * -name: Run daily test jobs: install: name: Install runs-on: ubuntu-latest steps: + - name: Only master + uses: actions/bin/filter@25b7b846d5027eac3315b50a8055ea675e2abd89 + with: + args: branch master - uses: actions/checkout@master - name: Install uses: actions/npm@59b64a598378f31e49cb76f27d6f3312b582f680 with: args: install - - name: Run testcases + - name: Run health check uses: actions/npm@59b64a598378f31e49cb76f27d6f3312b582f680 with: args: test:health-check + - name: Push health check + uses: ./actions/push-health-check + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/actions/deploy/Dockerfile b/actions/deploy/Dockerfile index 818834aa..fd688ec7 100644 --- a/actions/deploy/Dockerfile +++ b/actions/deploy/Dockerfile @@ -1,5 +1,5 @@ -FROM node:9 -LABEL "version"="0.0.7" +FROM node:12 +LABEL "version"="0.0.8" LABEL "com.github.actions.name"="Deploy" LABEL "com.github.actions.description"="Deploy just-news" LABEL "com.github.actions.icon"="archive" @@ -7,8 +7,7 @@ LABEL "com.github.actions.color"="orange" LABEL "repository"="https://github.com/disjukr/just-news/actions/deploy" LABEL "homepage"="https://github.com/disjukr/just-news/actions/deploy" -LABEL "maintainer"="item4 " +LABEL "maintainer"="JongChan Choi " ADD entrypoint.sh /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] - diff --git a/actions/deploy/entrypoint.sh b/actions/deploy/entrypoint.sh index e849e195..28a0260e 100755 --- a/actions/deploy/entrypoint.sh +++ b/actions/deploy/entrypoint.sh @@ -40,4 +40,3 @@ echo "git push origin release" git push origin release echo "popd" popd - diff --git a/actions/push-health-check/Dockerfile b/actions/push-health-check/Dockerfile new file mode 100644 index 00000000..7a9be042 --- /dev/null +++ b/actions/push-health-check/Dockerfile @@ -0,0 +1,13 @@ +FROM node:12 +LABEL "version"="0.0.0" +LABEL "com.github.actions.name"="Push health check" +LABEL "com.github.actions.description"="Push health check" +LABEL "com.github.actions.icon"="archive" +LABEL "com.github.actions.color"="orange" + +LABEL "repository"="https://github.com/disjukr/just-news/actions/deploy" +LABEL "homepage"="https://github.com/disjukr/just-news/actions/deploy" +LABEL "maintainer"="JongChan Choi " + +ADD entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/actions/push-health-check/entrypoint.sh b/actions/push-health-check/entrypoint.sh new file mode 100644 index 00000000..99f3ac16 --- /dev/null +++ b/actions/push-health-check/entrypoint.sh @@ -0,0 +1,38 @@ +#!/bin/bash +RELEASE_DIR=../just-news-push-health-check +BUILD_DIR=$(pwd) + +echo "npm run test:health-check" +npm run test:health-check + +echo "machine github.com login reactjs-bot password $GITHUB_TOKEN" >~/.netrc +git config --global user.name "just-news-bot" +git config --global user.email "jong+just.news@chan.moe" +git config --bool core.bare true + +echo "git clone release" +git clone https://github.com/disjukr/just-news.git $RELEASE_DIR +echo "pushd to RELEASE_DIR" +pushd $RELEASE_DIR + +echo "git checkout release" +git checkout health-check + +echo "copy files" +cp $BUILD_DIR/tmp/health-check.md health-check.md +cp $BUILD_DIR/tmp/health-check.png health-check.png +echo "git add -f ." +git add -f . + +echo "check git status" +git status +if git status | grep 'no changes added to commit'; then + exit +fi + +echo "git commit" +git commit -m "$(date)" +echo "git push origin health-check" +git push origin health-check +echo "popd" +popd diff --git a/src/test/health-check/index.ts b/src/test/health-check/index.ts index f26e3a75..45a5ac8b 100644 --- a/src/test/health-check/index.ts +++ b/src/test/health-check/index.ts @@ -9,6 +9,7 @@ import { fromJSON, } from '../..'; import imageReporter from './reporter/image'; +import markdownReporter from './reporter/markdown'; interface Case { @@ -185,7 +186,7 @@ const cases: Case[] = [ async function run() { const jobs = [...cases]; const jobResults: JobResult[] = []; - //* + /* const headless = false; const workers = [0, 1]; /*/ @@ -215,11 +216,13 @@ async function run() { } })); await imageReporter(jobResults, browser); + const markdownReport = await markdownReporter(jobResults, browser); await browser.close(); fs.writeFileSync( './tmp/health-check.json', JSON.stringify(jobResults, null, 4), ); + fs.writeFileSync('./tmp/health-check.md', markdownReport); } run().catch(e => { console.error(e ? (e.stack || e) : e);