update details #156
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: "Build, Test, Deploy" | |
on: | |
pull_request: #{ types: [ready_for_review] } | |
push: { branches: [main, 23gsoc/demoday] } | |
# schedule: | |
# - cron: "36 */5 * * *" | |
#release: { types: [published] } | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
env: | |
BUILD_PATH: /tmp/archive.tgz | |
NVM_DIR: /opt/nvm | |
BASH_ENV: /opt/nvm/nvm.sh | |
NODE_ENV: development | |
jobs: | |
bat: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone repo | |
uses: actions/checkout@v2 | |
- name: Setup nvm | |
shell: bash | |
run: | | |
mkdir -pv $NVM_DIR | |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash | |
- name: Install cms dependencies | |
run: | | |
cd cms | |
nvm install 16.13.0 | |
npm install | |
- name: Start cms | |
run: cd cms; npm run develop &> /tmp/cms.log & | |
env: | |
INITIALIZE_DATA: "true" | |
- name: Check cms running | |
uses: actions/github-script@v5 | |
env: | |
PORT: 1337 | |
LOG_FILE: /tmp/cms.log | |
with: | |
script: | | |
const http = require('http'); | |
const {readFileSync} = require('fs'); | |
core.info('waiting 1 minute for strapi data initialization to complete ..'); | |
await new Promise(zzz => setTimeout(zzz, 1 * 60 * 1000)); | |
http | |
.request(`http://localhost:${process.env.PORT}/_health`, { method: 'HEAD' }, r => { | |
if (r.statusCode === 204 && r.headers.strapi === 'You are so French!') | |
{ | |
core.info('cms successfully started') | |
return | |
} | |
core.error(readFileSync(process.env.LOG_FILE, 'utf-8')) | |
core.setFailed(`cms failed to start; returned status code: ${r.statusCode}; health status: ${r.headers.strapi}`); | |
}) | |
.on('error', core.setFailed) | |
.end(); | |
# - name: Check cms running | |
# run: | | |
# echo "Waiting 1 minute for strapi data initialization to complete.." | |
# sleep 1m # wait a moment grandpa | |
# _health=$(curl -s http://localhost:$PORT/_health -I | awk -F: '$1 == "strapi" { print $NF ~ /^[[:space:]]/ ? substr($NF, 2) : $NF }') || true | |
# status_code=$(curl -so/dev/null -w "%{http_code}" http://localhost:$PORT/_health -I) || true | |
# if [ $? -eq 7 ] || [ ${status_code:--999} -eq 000 ]; then | |
# echo "::error file=cms,title=cms_start_failure::" \ | |
# "cms failed to start, returned status code '${status_code:-NO_STATUS_CODE}'" | |
# exit 7 | |
# fi | |
# if [ "$_health" != "You are so French!" ]; then | |
# echo "::error file=cms,title=cms_unknown_error::" \ | |
# "cms started, but something else is wrong; returned status code '${status_code:-NO_STATUS_CODE}'" | |
# exit 1 | |
# fi | |
# echo "CMS successfully started" | |
# env: { PORT: 1337 } | |
- name: Install app dependencies | |
run: | | |
cd app | |
nvm i 16.13.0 | |
npm i | |
- name: Start app | |
run: | | |
cd app | |
npm run dev &>/tmp/app.log & | |
echo $! > /tmp/app.pid | |
- name: Check app running | |
uses: actions/github-script@v5 | |
env: { PORT: 3000, LOG_FILE: /tmp/app.log } | |
with: | |
script: | | |
const http = require('http'); | |
const {readFileSync} = require('fs'); | |
core.info('waiting 1 minute for app to start ..'); | |
await new Promise(zzz => setTimeout(zzz, 60 * 1000)); | |
http | |
.request(`http://localhost:${process.env.PORT}`, { method: 'GET' }, r => { | |
if (r.statusCode === 200) | |
{ | |
core.info('app successfully started') | |
return | |
} | |
core.error(readFileSync(process.env.LOG_FILE, 'utf8')) | |
core.setFailed(`app failed to start; returned status code: ${r.statusCode}; body: ${r.read()}`); | |
}) | |
.on('error', core.setFailed) | |
.end(); | |
- name: Start Open Event Server | |
run: | | |
sh startBackend.sh localhost production &>/tmp/open-event-server.log & | |
echo $! > /tmp/open-event-server.pid | |
- name: Check Open Event Server running | |
uses: actions/github-script@v5 | |
env: { PORT: 8080, LOG_FILE: /tmp/open-event-server.log } | |
with: | |
script: | | |
const http = require('http'); | |
const {readFileSync} = require('fs'); | |
core.info('waiting 1 minute for open-event-server to start ..'); | |
await new Promise(zzz => setTimeout(zzz, 60 * 1000)); | |
http | |
.request(`http://localhost:${process.env.PORT}`, { method: 'GET' }, r => { | |
if (r.statusCode === 200) | |
{ | |
core.info('open-event-server successfully started') | |
return | |
} | |
core.error(readFileSync(process.env.LOG_FILE, 'utf8')) | |
core.setFailed(`open-event-server failed to start; returned status code: ${r.statusCode}; body: ${r.read()}`); | |
}) | |
.on('error', core.setFailed) | |
.end(); | |
# - name: Check app running | |
# run: | | |
# echo "Waiting 10 seconds for app to start..." | |
# sleep 10s # wait a moment grandma | |
# status_code="$(curl -o /dev/null -s -w "%{http_code}\n" http://localhost:$PORT)" || true | |
# if { [ $? -eq 7 ] || [ ${status_code:--999} -eq 000 ]; }; then | |
# echo "::error file=app,title=app_start_failure::" \ | |
# "app failed to start, returned status code '${status_code:-NO_STATUS_CODE}'" | |
# exit 7 | |
# fi | |
# if [ "${status_code:--999}" -ne 200 ]; then | |
# echo "::error file=app,title=app_unknown_error::" \ | |
# "app started, but something else is wrong; returned status code '${status_code:-NO_STATUS_CODE}'" | |
# exit 1 | |
# fi | |
# echo "app successfully started" | |
# env: { PORT: 3000 } | |
- name: Build prod app | |
run: | | |
pkill -9 -F /tmp/app.pid | |
cd app; npm run build | |
env: | |
{ | |
NEXT_PUBLIC_STRAPI_API_URL: "http://localhost:1337", | |
NEXT_PUBLIC_EVENT_BACKEND_URL: "https://8188-49-43-26-241.ngrok-free.app", | |
NEXT_PUBLIC_DISCOURSE_HOST: "https://forums.rocket.chat", | |
DISCOURSE_HOST: "https://forums.rocket.chat", | |
} | |
- name: Generate archive | |
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }} | |
run: | | |
cd app | |
echo $GITHUB_SHA > /tmp/.github_sha | |
echo $GITHUB_REF > /tmp/.github_ref | |
tar zcvf ${{ env.BUILD_PATH }} \ | |
.next \ | |
ecosystem.config.js \ | |
next.config.js \ | |
package-lock.json \ | |
package.json \ | |
/tmp/.github_sha \ | |
/tmp/.github_ref | |
- name: Upload archive | |
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build | |
path: ${{ env.BUILD_PATH }} | |
# deploy: | |
# runs-on: ubuntu-latest | |
# if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }} # don't wanna run on prs | |
# needs: [bat] | |
# steps: | |
# - name: Download build archive | |
# uses: actions/download-artifact@v3 | |
# with: | |
# name: build | |
# path: /tmp/ | |
# # - name: Push archive | |
# # uses: easingthemes/ssh-deploy@main | |
# # env: | |
# # SOURCE: ${{ env.BUILD_PATH }} | |
# # TARGET: ${{ secrets.TARGET }} | |
# # REMOTE_HOST: ${{ secrets.REMOTE_HOST }} | |
# # REMOTE_USER: ${{ secrets.REMOTE_USER }} | |
# # REMOTE_PORT: ${{ secrets.REMOTE_PORT }} | |
# # SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
# # | |
# # - name: Start remote service | |
# # uses: appleboy/ssh-action@master | |
# # with: | |
# # host: ${{ secrets.REMOTE_HOST }} | |
# # port: ${{ secrets.REMOTE_PORT }} | |
# # username: ${{ secrets.REMOTE_USER }} | |
# # key: ${{ secrets.SSH_PRIVATE_KEY }} | |
# # script: | | |
# # target=${{ secrets.TARGET }} | |
# # build_path=${{ secrets.BUILD_PATH }} | |
# # cd $target | |
# # tar zxf $build_path | |
# # rm -f $build_path | |
# # npm install --production | |
# # pm2 reload ecosystem.config.js | |
# - name: Push archive and start service | |
# uses: debdutdeb/rc4community.deploy.action@main | |
# with: | |
# remote_host: ${{ secrets.REMOTE_HOST }} | |
# remote_port: ${{ secrets.REMOTE_PORT }} | |
# remote_user: ${{ secrets.REMOTE_USER }} | |
# ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} | |
# source: ${{ env.BUILD_PATH }} | |
# target: ${{ secrets.TARGET }} |