mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 02:11:44 +03:00
cb8ef8daa2
fixes https://github.com/TryGhost/Toolbox/issues/608 - this step will be waited on in CI config so we can ensure all tests have passed before automerging PRs
468 lines
15 KiB
YAML
468 lines
15 KiB
YAML
name: Test Suite
|
|
on:
|
|
pull_request:
|
|
push:
|
|
branches:
|
|
- main
|
|
- 'v5.*'
|
|
- 3.x
|
|
- 2.x
|
|
- 'renovate/*'
|
|
env:
|
|
FORCE_COLOR: 1
|
|
concurrency:
|
|
group: ${{ github.head_ref || github.run_id }}
|
|
cancel-in-progress: true
|
|
jobs:
|
|
lint:
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'push' || (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'renovate/'))
|
|
name: Lint
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- uses: actions/setup-node@v3
|
|
env:
|
|
FORCE_COLOR: 0
|
|
with:
|
|
node-version: '18.12.1'
|
|
cache: yarn
|
|
|
|
- uses: actions/cache@v3
|
|
with:
|
|
path: ghost/**/.eslintcache
|
|
key: eslint-cache
|
|
|
|
- run: yarn --prefer-offline
|
|
- run: yarn lint
|
|
- uses: tryghost/actions/actions/slack-build@main
|
|
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
with:
|
|
status: ${{ job.status }}
|
|
env:
|
|
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
|
|
|
|
admin-tests:
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'push' || (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'renovate/'))
|
|
name: Admin - Chrome
|
|
env:
|
|
MOZ_HEADLESS: 1
|
|
JOBS: 1
|
|
CI: true
|
|
COVERAGE: true
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- uses: actions/setup-node@v3
|
|
with:
|
|
node-version: "18.12.1"
|
|
|
|
- run: yarn --prefer-offline
|
|
- run: yarn workspace ghost-admin run test
|
|
env:
|
|
BROWSER: Chrome
|
|
|
|
# Merge coverage reports and upload
|
|
- run: yarn ember coverage-merge
|
|
working-directory: ghost/admin
|
|
- uses: actions/upload-artifact@v3
|
|
with:
|
|
name: admin-coverage
|
|
path: ghost/*/coverage/cobertura-coverage.xml
|
|
|
|
- uses: tryghost/actions/actions/slack-build@main
|
|
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
with:
|
|
status: ${{ job.status }}
|
|
env:
|
|
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
|
|
|
|
migrations:
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'push' || (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'renovate/'))
|
|
strategy:
|
|
matrix:
|
|
env:
|
|
- DB: sqlite3
|
|
DB_CLIENT: sqlite3
|
|
- DB: mysql8
|
|
DB_CLIENT: mysql
|
|
env:
|
|
database__client: ${{ matrix.env.DB_CLIENT }}
|
|
name: Migrations (${{ matrix.env.DB }})
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
submodules: true
|
|
- uses: actions/setup-node@v3
|
|
env:
|
|
FORCE_COLOR: 0
|
|
with:
|
|
node-version: '18.12.1'
|
|
cache: yarn
|
|
|
|
- name: Shutdown MySQL
|
|
run: sudo service mysql stop
|
|
if: matrix.env.DB == 'mysql8'
|
|
|
|
- uses: daniellockyer/mysql-action@main
|
|
if: matrix.env.DB == 'mysql8'
|
|
with:
|
|
authentication plugin: 'caching_sha2_password'
|
|
mysql version: '8.0'
|
|
mysql database: 'ghost_testing'
|
|
mysql root password: 'root'
|
|
|
|
- name: Set env vars (SQLite)
|
|
if: contains(matrix.env.DB, 'sqlite')
|
|
run: echo "database__connection__filename=/dev/shm/ghost-test.db" >> $GITHUB_ENV
|
|
|
|
- name: Set env vars (MySQL)
|
|
if: contains(matrix.env.DB, 'mysql')
|
|
run: |
|
|
echo "database__connection__host=127.0.0.1" >> $GITHUB_ENV
|
|
echo "database__connection__user=root" >> $GITHUB_ENV
|
|
echo "database__connection__password=root" >> $GITHUB_ENV
|
|
echo "database__connection__database=ghost_testing" >> $GITHUB_ENV
|
|
|
|
- run: yarn --prefer-offline
|
|
|
|
- name: Run Ghost and then kill it
|
|
run: yarn workspace ghost run start
|
|
env:
|
|
GHOST_TESTS_KILL_SERVER_AFTER_BOOT: true
|
|
|
|
- run: sqlite3 ${{ env.database__connection__filename }} "DELETE FROM migrations WHERE version LIKE '5.%';"
|
|
if: matrix.env.DB == 'sqlite3'
|
|
- run: mysql -h127.0.0.1 -uroot -proot ghost_testing -e "DELETE FROM migrations WHERE version LIKE '5.%';"
|
|
if: matrix.env.DB == 'mysql8'
|
|
|
|
- run: yarn knex-migrator migrate --force
|
|
|
|
unit-tests:
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'push' || (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'renovate/'))
|
|
strategy:
|
|
matrix:
|
|
node: [ '16.13.0', '18.12.1' ]
|
|
name: Unit Tests (Node ${{ matrix.node }})
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- uses: actions/setup-node@v3
|
|
env:
|
|
FORCE_COLOR: 0
|
|
with:
|
|
node-version: ${{ matrix.node }}
|
|
cache: yarn
|
|
|
|
- run: yarn --prefer-offline
|
|
- run: yarn test:unit
|
|
|
|
- uses: actions/upload-artifact@v3
|
|
if: startsWith(matrix.node, '18')
|
|
with:
|
|
name: unit-coverage
|
|
path: ghost/*/coverage/cobertura-coverage.xml
|
|
|
|
- uses: tryghost/actions/actions/slack-build@main
|
|
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
with:
|
|
status: ${{ job.status }}
|
|
env:
|
|
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
|
|
|
|
database-tests:
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'push' || (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'renovate/'))
|
|
strategy:
|
|
matrix:
|
|
node: [ '16.13.0', '18.12.1' ]
|
|
env:
|
|
- DB: mysql8
|
|
NODE_ENV: testing-mysql
|
|
include:
|
|
- node: 18.12.1
|
|
env:
|
|
DB: sqlite3
|
|
NODE_ENV: testing
|
|
env:
|
|
DB: ${{ matrix.env.DB }}
|
|
NODE_ENV: ${{ matrix.env.NODE_ENV }}
|
|
name: Database Tests (Node ${{ matrix.node }}, ${{ matrix.env.DB }})
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- uses: actions/setup-node@v3
|
|
env:
|
|
FORCE_COLOR: 0
|
|
with:
|
|
node-version: ${{ matrix.node }}
|
|
cache: yarn
|
|
|
|
- name: Shutdown MySQL
|
|
run: sudo service mysql stop
|
|
if: matrix.env.DB == 'mysql8'
|
|
|
|
- uses: daniellockyer/mysql-action@main
|
|
if: matrix.env.DB == 'mysql8'
|
|
with:
|
|
authentication plugin: 'caching_sha2_password'
|
|
mysql version: '8.0'
|
|
mysql database: 'ghost_testing'
|
|
mysql root password: 'root'
|
|
|
|
- name: Install dependencies
|
|
run: yarn --prefer-offline
|
|
|
|
- name: Record start time
|
|
run: date +%s > ${{ runner.temp }}/startTime # Get start time for test suite
|
|
|
|
- name: Set env vars (SQLite)
|
|
if: contains(matrix.env.DB, 'sqlite')
|
|
run: echo "database__connection__filename=/dev/shm/ghost-test.db" >> $GITHUB_ENV
|
|
|
|
- name: Set env vars (MySQL)
|
|
if: contains(matrix.env.DB, 'mysql')
|
|
run: echo "database__connection__password=root" >> $GITHUB_ENV
|
|
|
|
- name: E2E tests
|
|
working-directory: ghost/core
|
|
run: yarn test:ci:e2e
|
|
|
|
- name: Integration tests
|
|
working-directory: ghost/core
|
|
run: yarn test:ci:integration
|
|
|
|
# Get runtime in seconds for test suite
|
|
- name: Record test duration
|
|
run: |
|
|
startTime="$(cat ${{ runner.temp }}/startTime)"
|
|
endTime="$(date +%s)"
|
|
echo "test_time=$(($endTime-$startTime))" >> $GITHUB_ENV
|
|
|
|
- uses: actions/upload-artifact@v3
|
|
if: startsWith(matrix.node, '18') && contains(matrix.env.DB, 'mysql')
|
|
with:
|
|
name: e2e-coverage
|
|
path: |
|
|
ghost/*/coverage-e2e/cobertura-coverage.xml
|
|
ghost/*/coverage-integration/cobertura-coverage.xml
|
|
ghost/*/coverage-regression/cobertura-coverage.xml
|
|
|
|
# Continue on error if TailScale service is down
|
|
- name: Tailscale Action
|
|
timeout-minutes: 2
|
|
continue-on-error: true
|
|
if: (github.event_name == 'push' && github.repository_owner == 'TryGhost') || (github.event_name == 'pull_request' && startsWith(github.head_ref, 'TryGhost/'))
|
|
uses: tailscale/github-action@v1
|
|
with:
|
|
authkey: ${{ secrets.TAILSCALE_AUTHKEY }}
|
|
|
|
# Report time taken to metrics service
|
|
# Continue on error if previous TailScale step fails
|
|
- name: Store test duration
|
|
uses: tryghost/action-trigger-metric@main
|
|
timeout-minutes: 1
|
|
continue-on-error: true
|
|
if: (github.event_name == 'push' && github.repository_owner == 'TryGhost') || (github.event_name == 'pull_request' && startsWith(github.head_ref, 'TryGhost/'))
|
|
with:
|
|
metricName: 'test-time'
|
|
metricValue: ${{ env.test_time }}
|
|
configuration: |
|
|
{
|
|
"metrics": {
|
|
"transports": ["elasticsearch"],
|
|
"metadata": {
|
|
"database": "${{ matrix.env.DB }}",
|
|
"node": "${{ matrix.node }}"
|
|
}
|
|
},
|
|
"elasticsearch": {
|
|
"host": "${{ secrets.ELASTICSEARCH_HOST }}",
|
|
"username": "${{ secrets.ELASTICSEARCH_USERNAME }}",
|
|
"password": "${{ secrets.ELASTICSEARCH_PASSWORD }}"
|
|
}
|
|
}
|
|
|
|
- uses: tryghost/actions/actions/slack-build@main
|
|
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
with:
|
|
status: ${{ job.status }}
|
|
env:
|
|
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
|
|
|
|
regression-tests:
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'push' || (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'renovate/'))
|
|
strategy:
|
|
matrix:
|
|
include:
|
|
- node: 18.12.1
|
|
env:
|
|
DB: mysql8
|
|
NODE_ENV: testing-mysql
|
|
- node: 18.12.1
|
|
env:
|
|
DB: sqlite3
|
|
NODE_ENV: testing
|
|
env:
|
|
DB: ${{ matrix.env.DB }}
|
|
NODE_ENV: ${{ matrix.env.NODE_ENV }}
|
|
name: Regression Tests (Node ${{ matrix.node }}, ${{ matrix.env.DB }})
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- uses: actions/setup-node@v3
|
|
env:
|
|
FORCE_COLOR: 0
|
|
with:
|
|
node-version: ${{ matrix.node }}
|
|
cache: yarn
|
|
|
|
- name: Shutdown MySQL
|
|
run: sudo service mysql stop
|
|
if: matrix.env.DB == 'mysql8'
|
|
|
|
- uses: daniellockyer/mysql-action@main
|
|
if: matrix.env.DB == 'mysql8'
|
|
with:
|
|
authentication plugin: 'caching_sha2_password'
|
|
mysql version: '8.0'
|
|
mysql database: 'ghost_testing'
|
|
mysql root password: 'root'
|
|
|
|
- name: Install dependencies
|
|
run: yarn --prefer-offline
|
|
|
|
- name: Set env vars (SQLite)
|
|
if: contains(matrix.env.DB, 'sqlite')
|
|
run: echo "database__connection__filename=/dev/shm/ghost-test.db" >> $GITHUB_ENV
|
|
|
|
- name: Set env vars (MySQL)
|
|
if: contains(matrix.env.DB, 'mysql')
|
|
run: echo "database__connection__password=root" >> $GITHUB_ENV
|
|
|
|
- name: Regression tests
|
|
working-directory: ghost/core
|
|
run: yarn test:ci:regression
|
|
|
|
- uses: tryghost/actions/actions/slack-build@main
|
|
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
with:
|
|
status: ${{ job.status }}
|
|
env:
|
|
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
|
|
|
|
ghost-cli:
|
|
name: Ghost-CLI
|
|
if: github.event_name == 'push' || (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'renovate/'))
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
submodules: true
|
|
- uses: actions/setup-node@v3
|
|
env:
|
|
FORCE_COLOR: 0
|
|
with:
|
|
node-version: '16.13.0'
|
|
cache: yarn
|
|
|
|
- name: Install Ghost-CLI
|
|
run: npm install -g ghost-cli@latest
|
|
|
|
- run: yarn --prefer-offline
|
|
|
|
- run: npm --no-git-tag-version version minor # We need to artificially bump the minor version to get migrations to run
|
|
working-directory: ghost/core
|
|
|
|
- run: npm pack
|
|
working-directory: ghost/core
|
|
|
|
- run: mv ghost-*.tgz ghost.tgz
|
|
working-directory: ghost/core
|
|
|
|
- name: Clean Install
|
|
run: |
|
|
DIR=$(mktemp -d)
|
|
ghost install local -d $DIR --archive $(pwd)/ghost/core/ghost.tgz
|
|
|
|
- name: Latest Release
|
|
run: |
|
|
DIR=$(mktemp -d)
|
|
ghost install local -d $DIR
|
|
ghost update -d $DIR --archive $(pwd)/ghost/core/ghost.tgz
|
|
|
|
- name: Update from latest v4
|
|
run: |
|
|
DIR=$(mktemp -d)
|
|
ghost install v4 --local -d $DIR
|
|
ghost update -f -d $DIR --archive $(pwd)/ghost/core/ghost.tgz
|
|
|
|
- name: Print debug logs
|
|
if: failure()
|
|
run: |
|
|
[ -f ~/.ghost/logs/*.log ] && cat ~/.ghost/logs/*.log
|
|
|
|
- uses: tryghost/actions/actions/slack-build@main
|
|
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
with:
|
|
status: ${{ job.status }}
|
|
env:
|
|
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
|
|
|
|
coverage:
|
|
name: Coverage
|
|
needs: [unit-tests, admin-tests, database-tests]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
|
|
- name: Restore Admin coverage
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: admin-coverage
|
|
- name: Restore E2E coverage
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: e2e-coverage
|
|
|
|
- name: Move coverage
|
|
run: |
|
|
rsync -av --remove-source-files admin/* ghost/admin
|
|
rsync -av --remove-source-files core/* ghost/core
|
|
|
|
- name: Upload E2E test coverage
|
|
uses: codecov/codecov-action@v3
|
|
with:
|
|
flags: e2e-tests
|
|
move_coverage_to_trash: true
|
|
|
|
- name: Restore Unit test coverage
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: unit-coverage
|
|
path: coverage
|
|
- run: rsync -av --remove-source-files coverage/* ghost/
|
|
- name: Upload unit test coverage
|
|
uses: codecov/codecov-action@v3
|
|
with:
|
|
flags: unit-tests
|
|
|
|
check:
|
|
name: Allow Pull Request auto-merge
|
|
if: always() && github.event_name == 'pull_request'
|
|
needs: [lint, ghost-cli, admin-tests, migrations, unit-tests, database-tests, regression-tests]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Decide whether the needed jobs succeeded or failed
|
|
uses: re-actors/alls-green@release/v1
|
|
with:
|
|
jobs: ${{ toJSON(needs) }}
|
|
|
|
canary:
|
|
needs: [lint, ghost-cli, admin-tests, migrations, unit-tests, database-tests, regression-tests]
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
name: Canary
|
|
secrets: inherit
|
|
uses: tryghost/actions/.github/workflows/canary.yml@main
|