0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2024-12-30 22:34:01 -05:00

Merged setup steps in CI

- we don't need these to be separate steps and having them separate
  actually makes CI slower because it takes ~10-12s for GitHub to start
  new jobs
This commit is contained in:
Daniel Lockyer 2024-09-23 14:33:49 +02:00 committed by Daniel Lockyer
parent 7d441f24be
commit 5791be4937

View file

@ -31,9 +31,12 @@ concurrency:
cancel-in-progress: true
jobs:
job_get_metadata:
name: Metadata
job_setup:
name: Setup
runs-on: ubuntu-latest
timeout-minutes: 15
env:
IS_MAIN: ${{ github.ref == 'refs/heads/main' }}
permissions:
pull-requests: read
steps:
@ -106,28 +109,7 @@ jobs:
- 'apps/sodo-search/**'
any-code:
- '!**/*.md'
outputs:
changed_admin: ${{ steps.changed.outputs.admin }}
changed_core: ${{ steps.changed.outputs.core }}
changed_admin_x_settings: ${{ steps.changed.outputs.admin-x-settings }}
changed_announcement_bar: ${{ steps.changed.outputs.announcement-bar }}
changed_comments_ui: ${{ steps.changed.outputs.comments-ui }}
changed_portal: ${{ steps.changed.outputs.portal }}
changed_signup_form: ${{ steps.changed.outputs.signup-form }}
changed_sodo_search: ${{ steps.changed.outputs.sodo-search }}
changed_any_code: ${{ steps.changed.outputs.any-code }}
changed_new_package: ${{ steps.added.outputs.new-package }}
base_commit: ${{ env.BASE_COMMIT }}
is_canary_branch: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/arch') }}
is_main: ${{ github.ref == 'refs/heads/main' }}
has_browser_tests_label: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'browser-tests') }}
job_install_deps:
name: Install Dependencies
needs: job_get_metadata
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: 'Checkout current commit'
uses: actions/checkout@v4
with:
@ -154,7 +136,7 @@ jobs:
with:
path: .nxcache
key: nx-Linux-${{ github.ref }}-${{ env.HEAD_COMMIT }}
restore-keys: ${{needs.job_get_metadata.outputs.is_main == 'false' && env.NX_CACHE_RESTORE_KEYS || 'nx-never-restore'}}
restore-keys: ${{ env.IS_MAIN == 'false' && env.NX_CACHE_RESTORE_KEYS || 'nx-never-restore'}}
- name: Check dependency cache
uses: actions/cache@v4
@ -162,7 +144,7 @@ jobs:
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ env.cachekey }}
restore-keys: ${{needs.job_get_metadata.outputs.is_main == 'false' && env.DEPENDENCY_CACHE_RESTORE_KEYS || 'dep-never-restore'}}
restore-keys: ${{ env.IS_MAIN == 'false' && env.DEPENDENCY_CACHE_RESTORE_KEYS || 'dep-never-restore'}}
- name: Check build cache
uses: actions/cache@v4
@ -185,13 +167,28 @@ jobs:
- name: Build packages
if: steps.cache_built_packages.outputs.cache-hit != 'true'
run: yarn nx run-many -t build:ts
outputs:
changed_admin: ${{ steps.changed.outputs.admin }}
changed_core: ${{ steps.changed.outputs.core }}
changed_admin_x_settings: ${{ steps.changed.outputs.admin-x-settings }}
changed_announcement_bar: ${{ steps.changed.outputs.announcement-bar }}
changed_comments_ui: ${{ steps.changed.outputs.comments-ui }}
changed_portal: ${{ steps.changed.outputs.portal }}
changed_signup_form: ${{ steps.changed.outputs.signup-form }}
changed_sodo_search: ${{ steps.changed.outputs.sodo-search }}
changed_any_code: ${{ steps.changed.outputs.any-code }}
changed_new_package: ${{ steps.added.outputs.new-package }}
base_commit: ${{ env.BASE_COMMIT }}
is_canary_branch: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/arch') }}
is_main: ${{ env.IS_MAIN }}
has_browser_tests_label: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'browser-tests') }}
dependency_cache_key: ${{ env.cachekey }}
job_lint:
runs-on: ubuntu-latest
needs: [job_get_metadata, job_install_deps]
if: needs.job_get_metadata.outputs.changed_any_code == 'true'
needs: [job_setup]
if: needs.job_setup.outputs.changed_any_code == 'true'
name: Lint
steps:
- uses: actions/checkout@v4
@ -206,14 +203,14 @@ jobs:
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
DEPENDENCY_CACHE_KEY: ${{ needs.job_setup.outputs.dependency_cache_key }}
- uses: actions/cache@v4
with:
path: ghost/**/.eslintcache
key: eslint-cache
- run: yarn nx affected -t lint --base=${{ needs.job_get_metadata.outputs.BASE_COMMIT }}
- run: yarn nx affected -t lint --base=${{ needs.job_setup.outputs.BASE_COMMIT }}
- uses: tryghost/actions/actions/slack-build@main
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/main'
@ -224,13 +221,13 @@ jobs:
job_i18n:
runs-on: ubuntu-latest
needs: [job_get_metadata, job_install_deps]
needs: [job_setup]
name: i18n
if: |
needs.job_get_metadata.outputs.changed_comments_ui == 'true'
|| needs.job_get_metadata.outputs.changed_signup_form == 'true'
|| needs.job_get_metadata.outputs.changed_portal == 'true'
|| needs.job_get_metadata.outputs.changed_core == 'true'
needs.job_setup.outputs.changed_comments_ui == 'true'
|| needs.job_setup.outputs.changed_signup_form == 'true'
|| needs.job_setup.outputs.changed_portal == 'true'
|| needs.job_setup.outputs.changed_core == 'true'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
@ -240,15 +237,15 @@ jobs:
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
DEPENDENCY_CACHE_KEY: ${{ needs.job_setup.outputs.dependency_cache_key }}
- name: Run i18n tests
run: yarn nx run @tryghost/i18n:test
job_admin-tests:
runs-on: ubuntu-latest
needs: [job_get_metadata, job_install_deps]
if: needs.job_get_metadata.outputs.changed_admin == 'true'
needs: [job_setup]
if: needs.job_setup.outputs.changed_admin == 'true'
name: Admin tests - Chrome
env:
MOZ_HEADLESS: 1
@ -264,7 +261,7 @@ jobs:
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
DEPENDENCY_CACHE_KEY: ${{ needs.job_setup.outputs.dependency_cache_key }}
- run: yarn nx run ghost-admin:test
env:
@ -291,8 +288,8 @@ jobs:
timeout-minutes: 60
runs-on:
labels: ubuntu-latest
needs: [job_get_metadata, job_install_deps]
if: needs.job_get_metadata.outputs.changed_any_code == 'true' && (needs.job_get_metadata.outputs.is_main == 'true' || needs.job_get_metadata.outputs.has_browser_tests_label == 'true')
needs: [job_setup]
if: needs.job_setup.outputs.changed_any_code == 'true' && (needs.job_setup.outputs.is_main == 'true' || needs.job_setup.outputs.has_browser_tests_label == 'true')
concurrency:
group: ${{ github.workflow }}
steps:
@ -317,7 +314,7 @@ jobs:
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
DEPENDENCY_CACHE_KEY: ${{ needs.job_setup.outputs.dependency_cache_key }}
- name: Run migrations
working-directory: ghost/core
@ -366,8 +363,8 @@ jobs:
job_perf-tests:
runs-on:
labels: ubuntu-latest-4-cores
needs: [job_get_metadata, job_install_deps]
if: needs.job_get_metadata.outputs.changed_core == 'true' && needs.job_get_metadata.outputs.is_main == 'true'
needs: [job_setup]
if: needs.job_setup.outputs.changed_core == 'true' && needs.job_setup.outputs.is_main == 'true'
name: Performance tests
steps:
- uses: actions/checkout@v4
@ -382,7 +379,7 @@ jobs:
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
DEPENDENCY_CACHE_KEY: ${{ needs.job_setup.outputs.dependency_cache_key }}
- name: Install hyperfine
run: |
@ -413,8 +410,8 @@ jobs:
job_unit-tests:
runs-on: ubuntu-latest
needs: [job_get_metadata, job_install_deps]
if: needs.job_get_metadata.outputs.changed_any_code == 'true'
needs: [job_setup]
if: needs.job_setup.outputs.changed_any_code == 'true'
strategy:
matrix:
node: [ '18.12.1', '20.11.1' ]
@ -432,9 +429,9 @@ jobs:
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
DEPENDENCY_CACHE_KEY: ${{ needs.job_setup.outputs.dependency_cache_key }}
- run: yarn nx affected -t test:unit --base=${{ needs.job_get_metadata.outputs.BASE_COMMIT }}
- run: yarn nx affected -t test:unit --base=${{ needs.job_setup.outputs.BASE_COMMIT }}
- uses: actions/upload-artifact@v4
if: startsWith(matrix.node, '18')
@ -451,8 +448,8 @@ jobs:
job_database-tests:
runs-on: ubuntu-latest
needs: [job_get_metadata, job_install_deps]
if: needs.job_get_metadata.outputs.changed_core == 'true'
needs: [job_setup]
if: needs.job_setup.outputs.changed_core == 'true'
strategy:
matrix:
node: [ '18.12.1', '20.11.1' ]
@ -491,7 +488,7 @@ jobs:
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
DEPENDENCY_CACHE_KEY: ${{ needs.job_setup.outputs.dependency_cache_key }}
- name: Record start time
run: date +%s > ${{ runner.temp }}/startTime # Get start time for test suite
@ -572,8 +569,8 @@ jobs:
job_regression-tests:
runs-on: ubuntu-latest
needs: [job_get_metadata, job_install_deps]
if: needs.job_get_metadata.outputs.changed_core == 'true'
needs: [job_setup]
if: needs.job_setup.outputs.changed_core == 'true'
strategy:
matrix:
include:
@ -614,7 +611,7 @@ jobs:
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
DEPENDENCY_CACHE_KEY: ${{ needs.job_setup.outputs.dependency_cache_key }}
- name: Set env vars (SQLite)
if: contains(matrix.env.DB, 'sqlite')
@ -637,8 +634,8 @@ jobs:
job_admin_x_settings:
runs-on: ubuntu-latest
needs: [job_get_metadata, job_install_deps]
if: needs.job_get_metadata.outputs.changed_admin_x_settings == 'true'
needs: [job_setup]
if: needs.job_setup.outputs.changed_admin_x_settings == 'true'
name: Admin-X Settings tests
env:
CI: true
@ -653,7 +650,7 @@ jobs:
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
DEPENDENCY_CACHE_KEY: ${{ needs.job_setup.outputs.dependency_cache_key }}
- name: Get Playwright version
id: playwright-version
@ -690,8 +687,8 @@ jobs:
job_comments_ui:
runs-on: ubuntu-latest
needs: [job_get_metadata, job_install_deps]
if: needs.job_get_metadata.outputs.changed_comments_ui == 'true'
needs: [job_setup]
if: needs.job_setup.outputs.changed_comments_ui == 'true'
name: Comments-UI tests
env:
CI: true
@ -706,7 +703,7 @@ jobs:
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
DEPENDENCY_CACHE_KEY: ${{ needs.job_setup.outputs.dependency_cache_key }}
- name: Get Playwright version
id: playwright-version
@ -743,8 +740,8 @@ jobs:
job_signup_form:
runs-on: ubuntu-latest
needs: [job_get_metadata, job_install_deps]
if: needs.job_get_metadata.outputs.changed_signup_form == 'true'
needs: [job_setup]
if: needs.job_setup.outputs.changed_signup_form == 'true'
name: Signup-form tests
env:
CI: true
@ -759,7 +756,7 @@ jobs:
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
DEPENDENCY_CACHE_KEY: ${{ needs.job_setup.outputs.dependency_cache_key }}
- name: Get Playwright version
id: playwright-version
@ -796,8 +793,8 @@ jobs:
job_ghost-cli:
name: Ghost-CLI tests
needs: [job_get_metadata, job_install_deps]
if: needs.job_get_metadata.outputs.changed_core == 'true'
needs: [job_setup]
if: needs.job_setup.outputs.changed_core == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
@ -816,7 +813,7 @@ jobs:
- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
DEPENDENCY_CACHE_KEY: ${{ needs.job_setup.outputs.dependency_cache_key }}
- 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
@ -923,8 +920,7 @@ jobs:
name: All required tests passed or skipped
needs:
[
job_get_metadata,
job_install_deps,
job_setup,
job_lint,
job_i18n,
job_ghost-cli,
@ -950,12 +946,12 @@ jobs:
canary:
needs: [
job_get_metadata,
job_setup,
job_required_tests
]
name: Canary
runs-on: ubuntu-latest
if: always() && needs.job_get_metadata.outputs.is_canary_branch == 'true' && needs.job_required_tests.result == 'success' && needs.job_get_metadata.result == 'success'
if: always() && needs.job_setup.outputs.is_canary_branch == 'true' && needs.job_setup.result == 'success' && needs.job_setup.result == 'success'
steps:
- name: Output needs (for debugging)
run: echo "${{ toJson(needs) }}"