Skip to content

ci: add AutoPR workflow, relying on OPENAI_API_KEY env var #1031

ci: add AutoPR workflow, relying on OPENAI_API_KEY env var

ci: add AutoPR workflow, relying on OPENAI_API_KEY env var #1031

Workflow file for this run

name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
FORCE_COLOR: '3' # asks Chalk to use colors in logs of Yarn, Jest, ESLint and many others
jobs:
code-checks:
name: Code checks
if: "!contains(github.event.head_commit.message, '[skip ci]')"
timeout-minutes: 5
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: npm install
env:
CI: true
run: npm install --prefer-offline --no-audit
- name: npm run build
run: |
npm run build
git status
echo ℹ️ If this test fails, run `npm run build` and commit the changes.
exit $(git diff | wc -l)
- name: npm run lint:typescript
run: |
npm run lint:typescript
git status
echo ℹ️ If this test fails, run `npm run lint:typescript` and commit the changes.
exit $(git diff | wc -l)
- name: npm run lint:fix
run: |
npm run lint:fix
git status
echo ℹ️ If this test fails, run `npm run lint:fix` and commit the changes.
exit $(git diff | wc -l)
- name: npm run lint:format
run: |
npm run lint:format
git status
echo ℹ️ If this test fails, run `npm run lint:format` and commit the changes.
exit $(git diff | wc -l)
- name: JSDoc type checks
run: |
npx tsc --target es2015 --moduleResolution node --noEmit --allowJs `find app/ -name "*.js"`
approval-tests:
name: Approval tests
if: "!contains(github.event.head_commit.message, '[skip ci]')"
timeout-minutes: 5
runs-on: ubuntu-20.04
services:
mongodb:
image: docker://mongo:3.4
ports:
- 27017:27017
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- uses: c-py/action-dotenv-to-setenv@v2
with:
env-file: env-vars-testing.conf
- name: npm install
env:
CI: true
run: npm install --prefer-offline --no-audit
- name: Initialize database
env:
CI: true
run: npm run test-reset
- name: Start Openwhyd server
run: |
npm run start:coverage --mongoDbDatabase openwhyd_test &
./scripts/wait-for-http-server.sh 8080 # give openwhyd's server some time to start
- name: Approval tests
env:
PORT: '8080'
DONT_KILL: '1'
MONGODB_URL: 'mongodb://localhost:27017/openwhyd_test'
run: npx ava test/approval.tests.js
- name: Approval tests for Hot Tracks
env:
PORT: '8080'
DONT_KILL: '1'
MONGODB_URL: 'mongodb://localhost:27017/openwhyd_test'
run: npx jest --runInBand test/approval-hot-tracks.jest.test.js
- name: Get coverage data
run: |
sleep 2 # give some time for nyc (npm run start:coverage) to save coverage info
killall node
sleep 2 # give some time for nyc (npm run start:coverage) to save coverage info
npx nyc report --reporter=lcov # stores the coverage report in coverage/lcov.info
- name: Save code coverage results
uses: actions/upload-artifact@v3
with:
name: approval-code-coverage-report
path: |
.nyc_output
coverage
approval-tests-2:
name: Approval tests for /api/post
if: "!contains(github.event.head_commit.message, '[skip ci]')"
timeout-minutes: 5
runs-on: ubuntu-20.04
services:
mongodb:
image: docker://mongo:3.4
ports:
- 27117:27017
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- uses: c-py/action-dotenv-to-setenv@v2
with:
env-file: env-vars-testing.conf
- name: npm install
env:
CI: true
run: npm install --prefer-offline --no-audit
- name: Approval tests
run: npm run test:approval
unit-tests:
name: Unit tests
if: "!contains(github.event.head_commit.message, '[skip ci]')"
timeout-minutes: 5
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: npm install
env:
CI: true
run: npm install --prefer-offline --no-audit
- name: Unit tests
env:
CI: true
run: npm run test:unit
functional-tests:
name: Functional tests
if: "!contains(github.event.head_commit.message, '[skip ci]')"
timeout-minutes: 5
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: npm install
env:
CI: true
run: npm install --prefer-offline --no-audit
- name: Functional tests
env:
CI: true
run: npm run test:functional
integration-tests:
name: Integration tests
if: "!contains(github.event.head_commit.message, '[skip ci]')"
timeout-minutes: 5
runs-on: ubuntu-20.04
services:
mongodb:
image: docker://mongo:3.4
ports:
- 27017:27017
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- uses: c-py/action-dotenv-to-setenv@v2
with:
env-file: env-vars-testing.conf
- name: npm install
env:
CI: true
run: npm install --prefer-offline --no-audit
- name: Initialize database
env:
CI: true
run: npm run test-reset
- name: Start Openwhyd server
run: |
npm start --mongoDbDatabase openwhyd_test &
./scripts/wait-for-http-server.sh 8080 # give openwhyd's server some time to start
- name: API tests
env:
CI: true
run: npm run test:integration
refactor-coverage:
name: Send test coverage of the `post` API to Codacy
if: "!contains(github.event.head_commit.message, '[skip ci]')"
timeout-minutes: 5
runs-on: ubuntu-20.04
services:
mongodb:
image: docker://mongo:3.4
ports:
- 27117:27017
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- uses: c-py/action-dotenv-to-setenv@v2
with:
env-file: env-vars-testing.conf
- name: npm install
env:
CI: true
run: npm install --prefer-offline --no-audit
- run: npm run test:post:coverage
env:
CI: true
MONGODB_HOST: localhost
MONGODB_PORT: 27117
- name: Save code coverage results
uses: actions/upload-artifact@v3
with:
name: refactor-code-coverage-report
path: |
.nyc_output
coverage
cypress-tests:
name: Cypress E2E tests
if: "!contains(github.event.head_commit.message, '[skip ci]')"
timeout-minutes: 5
runs-on: ubuntu-20.04
services:
mongodb:
image: docker://mongo:3.4
ports:
- 27017:27017
strategy:
# when one test fails, DO NOT cancel the other
# containers, because this will kill Cypress processes
# leaving the Dashboard hanging ...
# https://github.com/cypress-io/github-action/issues/48
fail-fast: false
matrix:
# run 3 copies of the current job in parallel
containers: [1, 2, 3]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '${{ steps.nvmrc.outputs.node_version }}'
cache: 'npm'
- uses: c-py/action-dotenv-to-setenv@v2
with:
env-file: env-vars-testing.conf
- name: npm install
env:
CI: true
run: npm install --prefer-offline --no-audit
- name: Run Cypress tests against Openwhyd server
uses: cypress-io/github-action@v5.0.2
with:
start: npm run start:coverage --mongoDbDatabase openwhyd_test
wait-on: 'http://localhost:8080'
config-file: cypress.config.ts
browser: 'chromium' # to include browser console in cypress logs
record: true
parallel: true
env:
CI: true
APPLITOOLS_API_KEY: ${{ secrets.APPLITOOLS_API_KEY }}
# pass the Dashboard record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# Recommended: pass the GitHub token lets this action correctly
# determine the unique run id necessary to re-run the checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# DEBUG: 'cypress:server:socket-base'
- name: Get coverage data
run: |
# npm run test:coverage
npx nyc report --reporter=lcov # stores the coverage report in coverage/lcov.info
- name: Save code coverage results
uses: actions/upload-artifact@v3
with:
name: cypress-code-coverage-report
path: |
.nyc_output
coverage
# NOTE: screenshots will be generated only if E2E test failed
- uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
# Test run video was always captured, so this action uses "always()" condition
- uses: actions/upload-artifact@v3
if: always()
with:
name: cypress-videos
path: cypress/videos
coverage:
name: Send coverage reports to Codacy
needs:
- cypress-tests
- approval-tests
- refactor-coverage
# TODO: add coverage for unit and integration tests too
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: cypress-code-coverage-report
path: coverage-cypress/
- uses: actions/download-artifact@v3
with:
name: approval-code-coverage-report
path: coverage-approval/
- uses: actions/download-artifact@v3
with:
name: refactor-code-coverage-report
path: coverage-refactor/
- name: Merge coverage reports
run: |
mkdir .nyc_output
mkdir coverage-reports
cp coverage-cypress/.nyc_output/*.json coverage-reports
cp coverage-approval/.nyc_output/*.json coverage-reports
cp coverage-refactor/.nyc_output/*.json coverage-reports
npx nyc merge coverage-reports .nyc_output/merged-coverage.json
npx nyc report --reporter=lcov --reporter=text # stores the coverage report in coverage/lcov.info
- uses: codacy/codacy-coverage-reporter-action@master
with:
project-token: ${{ secrets.CODACY_REPOSITORY_TOKEN_FOR_COVERAGE }}
coverage-reports: coverage/lcov.info
release:
name: Release
needs:
- unit-tests
- integration-tests
- cypress-tests
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
# to prevent "You're not authorized to push to this branch"
persist-credentials: false
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm install --prefer-offline --no-audit
if: github.event_name == 'push'
- name: npx semantic-release
run: |
# we install just semantic-release and its plugins, without considering package.json
mkdir "tmp-release"
npm --prefix "tmp-release" install --no-save \
"semantic-release@17.3.1" \
"@semantic-release/changelog@5.0.1" \
"@semantic-release/git@9.0.0" \
&& $(npm --prefix "tmp-release" bin)/semantic-release
rm -rf "tmp-release"
env:
CI: true
GH_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Create Docker tags
id: create_docker_tags
run: |
echo "tags=latest,$(git tag -l --sort=-v:refname | head -1 | cut -c 2-)" >> $GITHUB_OUTPUT
# from https://github.com/jerray/publish-docker-action/issues/11#issuecomment-607077257
- name: Publish to Docker Hub registry
if: github.event_name == 'push'
uses: jerray/publish-docker-action@v1.0.3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
tags: ${{ steps.create_docker_tags.outputs.tags }}
docker:
# To publish the Docker image from here, see https://github.com/openwhyd/openwhyd/pull/308/commits/1eacaa98885789642ba0073c9bb4d822021f0d95#diff-12a86cef0c4707531fdbabac3e38cb2aR36
name: Docker tests
timeout-minutes: 5
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Build and start services
run: docker-compose up --build --detach
- name: Init database for tests
run: |
docker-compose exec -T web npm run test-reset
docker-compose restart web
docker-compose exec -T web sh -c './scripts/wait-for-http-server.sh 8080'
- name: Run unit tests
run: docker-compose exec -T web npm run test:unit
- name: Run API tests
run: docker-compose exec -T web npm run test:integration
- name: Logs from docker-compose
if: ${{ always() }} # this step is useful to troubleshoot the execution of openwhyd when tests fail
run: docker-compose logs