Skip to content

Commit c6374f6

Browse files
committed
chore(gh-actions): import
1 parent f741680 commit c6374f6

File tree

10 files changed

+865
-0
lines changed

10 files changed

+865
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: "Run Marketing UI Tests"
2+
description: "Runs the marketing UI tests"
3+
4+
inputs:
5+
CONTENTFUL_SPACE_ID:
6+
description: "Contentful Space ID"
7+
required: true
8+
DRAFT_MODE_TOKEN:
9+
description: "Marketing App Draft Mode Token"
10+
required: true
11+
APPLITOOLS_API_KEY:
12+
description: "Applitools API Key"
13+
required: true
14+
APPLICATION_BASE_ADDRESS:
15+
description: "The base URL for the application. Defaults to http://code.marketing-sites.localhost:3001"
16+
default: "code.marketing-sites.localhost:3001"
17+
ENVIRONMENT_TYPE:
18+
description: "local, pr, test, or production"
19+
required: true
20+
SHARD_INDEX:
21+
description: "The shard index to use for the tests."
22+
required: true
23+
SHARD_TOTAL:
24+
description: "The total number of shards to use for the tests."
25+
required: true
26+
GITHUB_ENVIRONMENT_NAME:
27+
description: "The name of the GitHub environment to use for this action"
28+
required: false
29+
BRANCHED_TESTING_ENABLED:
30+
description: "Whether branched testing is enabled. Defaults to false"
31+
default: "false"
32+
required: false
33+
PR_HEAD_REF:
34+
description: "The head ref of the pull request."
35+
required: false
36+
SITE_TYPE:
37+
description: "The type of site being tested. Defaults to 'corporate'."
38+
default: "corporate"
39+
required: false
40+
41+
runs:
42+
using: composite
43+
44+
steps:
45+
- name: Prepare UI Test Environment
46+
shell: bash
47+
working-directory: ./apps/marketing
48+
run: |
49+
echo "APPLITOOLS_API_KEY=${{ inputs.APPLITOOLS_API_KEY }}
50+
DRAFT_MODE_TOKEN=${{ inputs.DRAFT_MODE_TOKEN }}
51+
CI=true
52+
STAGE=${{ inputs.ENVIRONMENT_TYPE }}
53+
NEXT_PUBLIC_STAGE=${{ inputs.ENVIRONMENT_TYPE }}
54+
APPLICATION_BASE_ADDRESS=${{ inputs.APPLICATION_BASE_ADDRESS }}
55+
BRANCHED_TESTING_ENABLED=${{ inputs.BRANCHED_TESTING_ENABLED }}
56+
PR_HEAD_REF=${{ inputs.PR_HEAD_REF }}
57+
SITE_TYPE=${{ inputs.SITE_TYPE }}
58+
" >> .env
59+
60+
- name: UI Tests
61+
shell: bash
62+
# If updating playwright, also update the version in package.json
63+
run: |
64+
docker run --network host \
65+
--env-file ./apps/marketing/.env \
66+
-v $PWD:/workspace \
67+
-w /workspace\
68+
mcr.microsoft.com/playwright:v1.49.1-noble \
69+
bash -c "corepack enable && HOME=/root yarn workspace @code-dot-org/marketing test:ui:ci --shard ${{ inputs.SHARD_INDEX }}/${{ inputs.SHARD_TOTAL }}"
70+
working-directory: ./
71+
72+
- name: Upload shard blob report to GitHub Actions Artifacts
73+
if: ${{ !cancelled() }}
74+
uses: actions/upload-artifact@v4
75+
with:
76+
name: blob-report-${{ inputs.GITHUB_ENVIRONMENT_NAME || 'pr' }}-${{ inputs.SHARD_INDEX }}
77+
path: ./apps/marketing/blob-report
78+
retention-days: 1
79+
80+
- name: Run Google Lighthouse Audits
81+
uses: treosh/lighthouse-ci-action@9917efea514615fb2ff2890f5b8be2d51e703b6e
82+
# Only run lighthouse audits once
83+
if: inputs.SHARD_INDEX == '1'
84+
env:
85+
HTTP_PROTOCOL: ${{ inputs.APPLICATION_BASE_ADDRESS == 'code.marketing-sites.localhost:3001' && 'http' || 'https' }}
86+
with:
87+
urls: ${{ env.HTTP_PROTOCOL }}://${{ inputs.APPLICATION_BASE_ADDRESS }}/en-US/engineering/all-the-things
88+
uploadArtifacts: true
89+
temporaryPublicStorage: true
90+
configPath: "./apps/marketing/.lighthouserc.js"
91+
artifactName: "lighthouse-report-${{ inputs.GITHUB_ENVIRONMENT_NAME || 'local' }}"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: "Merge Playwright Test Reports"
2+
description: "Merges playwright test reports from multiple shards into one single report"
3+
4+
inputs:
5+
GITHUB_ENVIRONMENT_NAME:
6+
description: "The name of the GitHub environment to use for this action"
7+
default: "pr"
8+
required: false
9+
10+
runs:
11+
using: composite
12+
steps:
13+
- name: Setup Frontend
14+
uses: ./.github/actions/frontend/setup
15+
16+
- name: Download blob reports from GitHub Actions Artifacts
17+
uses: actions/download-artifact@v4
18+
with:
19+
path: all-blob-reports
20+
pattern: blob-report-${{ inputs.GITHUB_ENVIRONMENT_NAME }}-*
21+
merge-multiple: true
22+
23+
- name: Merge into HTML Report
24+
shell: bash
25+
run: yarn dlx playwright merge-reports --reporter html ./all-blob-reports
26+
27+
- name: Upload HTML report
28+
uses: actions/upload-artifact@v4
29+
with:
30+
name: html-report--attempt-${{ inputs.GITHUB_ENVIRONMENT_NAME }}-${{ github.run_attempt }}
31+
path: playwright-report
32+
retention-days: 1
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: "Install & Setup Frontend Directory"
2+
description: "Setup for the frontend directory"
3+
4+
inputs:
5+
INSTALL_DEPENDENCIES:
6+
description: "Whether to install dependencies. Defaults to true"
7+
default: "true"
8+
required: false
9+
10+
runs:
11+
using: composite
12+
steps:
13+
- name: Enable Corepack before setting up Node
14+
shell: bash
15+
run: corepack enable
16+
17+
- name: Cache turborepo
18+
uses: rharkor/caching-for-turbo@a1c4079258ae08389be75b57d4d7a70f23c1c66d # v1.8
19+
20+
- uses: actions/setup-node@v4
21+
if: inputs.INSTALL_DEPENDENCIES == 'true'
22+
with:
23+
node-version-file: ".nvmrc"
24+
cache: "yarn"
25+
cache-dependency-path: 'yarn.lock'
26+
27+
- name: Install dependencies
28+
if: inputs.INSTALL_DEPENDENCIES == 'true'
29+
shell: bash
30+
run: yarn install
31+
working-directory: ./
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Component-Library-CI
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-24.04
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: Setup Frontend
14+
uses: ./.github/actions/frontend/setup
15+
16+
- name: Install Playwright for Design System Storybook
17+
run: npx playwright install --with-deps
18+
working-directory: ./apps/design-system-storybook
19+
20+
- name: Build
21+
run: yarn build --filter @code-dot-org/component-library --filter @code-dot-org/design-system-storybook
22+
working-directory: ./
23+
24+
- name: Lint
25+
run: yarn lint --filter @code-dot-org/component-library --filter @code-dot-org/design-system-storybook
26+
working-directory: ./
27+
28+
- name: Unit Tests
29+
run: yarn test --filter @code-dot-org/component-library --filter @code-dot-org/design-system-storybook
30+
working-directory: ./
31+
32+
- name: UI Tests
33+
run: yarn test:ui:ci --filter @code-dot-org/component-library --filter @code-dot-org/design-system-storybook
34+
working-directory: ./
35+
36+
- name: Upload static files as pages artifact
37+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call'
38+
id: deployment
39+
uses: actions/upload-pages-artifact@v3
40+
with:
41+
path: apps/design-system-storybook/dist
42+
name: component-library-storybook
43+
44+
eyes:
45+
runs-on: ubuntu-24.04
46+
47+
permissions:
48+
pull-requests: write
49+
issues: write
50+
51+
steps:
52+
- uses: actions/checkout@v4
53+
54+
- name: Setup Frontend
55+
uses: ./.github/actions/frontend/setup
56+
57+
- name: Build
58+
run: yarn build --filter @code-dot-org/design-system-storybook
59+
working-directory: ./
60+
61+
- name: Eyes Tests
62+
id: eyes
63+
run: |
64+
EYES_REPORT=$(COREPACK_ENABLE_DOWNLOAD_PROMPT=0 yarn eyes-storybook)
65+
echo "$EYES_REPORT"
66+
# Send multiline report to environment var
67+
echo "EYES_REPORT<<EOF" >> $GITHUB_OUTPUT
68+
echo "$EYES_REPORT" >> $GITHUB_OUTPUT
69+
echo "EOF" >> $GITHUB_OUTPUT
70+
# Check if the report was successful, failing if not.
71+
if echo "$EYES_REPORT" | grep -q "✅"; then
72+
echo "✅ Eyes report was successful, exiting with 0"
73+
exit 0
74+
else
75+
echo "❌ Eyes report unsuccessful, exiting with 1"
76+
exit 1
77+
fi
78+
working-directory: ./apps/design-system-storybook
79+
continue-on-error: ${{ github.event_name == 'pull_request' }}
80+
env:
81+
APPLITOOLS_API_KEY: ${{ secrets.APPLITOOLS_API_KEY }}
82+
83+
- name: Find Report Comment
84+
if: github.event.pull_request.number
85+
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
86+
id: eyes-report-comment
87+
with:
88+
issue-number: ${{ github.event.pull_request.number }}
89+
comment-author: 'github-actions[bot]'
90+
body-includes: 'Visual Comparison Report'
91+
92+
- name: Create comment (if not exists)
93+
if: github.event.pull_request.number && steps.eyes-report-comment.outputs.comment-id == ''
94+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
95+
with:
96+
issue-number: ${{ github.event.pull_request.number }}
97+
body: ${{ steps.eyes.outputs.EYES_REPORT }}
98+
99+
- name: Update comment (if exists)
100+
if: github.event.pull_request.number && steps.eyes-report-comment.outputs.comment-id != ''
101+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
102+
with:
103+
comment-id: ${{ steps.eyes-report-comment.outputs.comment-id }}
104+
edit-mode: replace
105+
body: ${{ steps.eyes.outputs.EYES_REPORT }}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Component-Library-Deploy
2+
3+
on:
4+
workflow_dispatch:
5+
6+
push:
7+
branches:
8+
- staging
9+
- staging-next
10+
paths:
11+
- 'packages/component-library/**'
12+
- 'packages/component-library-styles/**'
13+
- 'shared/**'
14+
15+
jobs:
16+
ci:
17+
uses: ./.github/workflows/component-library-ci.yml
18+
secrets: inherit
19+
20+
deploy:
21+
needs:
22+
- ci
23+
24+
permissions:
25+
contents: read
26+
pages: write
27+
id-token: write
28+
29+
environment:
30+
name: component-library-storybook
31+
32+
runs-on: ubuntu-24.04
33+
34+
steps:
35+
- name: Deploy to GitHub Pages
36+
uses: actions/deploy-pages@v4
37+
with:
38+
artifact_name: "component-library-storybook"

.github/workflows/frontend-ci.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Common workflow for execution of continuous integration for the `frontend` code base.
2+
# This workflow handles setup and teardown for parallel workflow execution for the various apps and packages in `frontend`.
3+
name: Frontend-CI
4+
5+
on:
6+
pull_request:
7+
branches:
8+
- staging
9+
- staging-next
10+
11+
env:
12+
APPLITOOLS_BATCH_ID: ${{ github.event.pull_request.head.sha || github.sha }}
13+
14+
jobs:
15+
# Initializes common variables and environment prior to executing other jobs
16+
setup:
17+
runs-on: ubuntu-24.04
18+
outputs:
19+
component-library-changed: ${{ steps.changes.outputs.component-library }}
20+
steps:
21+
# Determine what changed to later skip workflows
22+
# Github Actions does not offer conditional runtime path filtering, thus use this action to calculate the
23+
# changes. Root level applications (such as marketing) are not skipped as its dependency tree always changes
24+
- name: Get Change Sets
25+
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
26+
id: changes
27+
with:
28+
filters: |
29+
component-library:
30+
- 'apps/design-system-storybook/**'
31+
- 'packages/component-library/**'
32+
- 'packages/component-library-styles/**'
33+
- 'packages/fonts/**'
34+
- '*'
35+
36+
# Start the marketing app CI workflow
37+
marketing:
38+
needs: setup
39+
uses: ./.github/workflows/marketing-app-ci.yml
40+
with:
41+
BRANCHED_TESTING_ENABLED: ${{ contains( github.event.pull_request.labels.*.name, 'All The Things') }}
42+
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
43+
secrets: inherit
44+
45+
# Start the component library CI workflow
46+
component-library:
47+
if: ${{ needs.setup.outputs.component-library-changed == 'true' }}
48+
needs: setup
49+
uses: ./.github/workflows/component-library-ci.yml
50+
secrets: inherit
51+
52+
# Common teardown actions that must occur after _all_ workflows have completed.
53+
# For example, closing the Applitools batch after its completion.
54+
teardown:
55+
needs: [setup, marketing, component-library]
56+
if: always()
57+
runs-on: ubuntu-24.04
58+
steps:
59+
# Close the eyes batch after all distributed eyes tests have completed
60+
- name: Update Applitools batch status
61+
shell: bash
62+
run: |
63+
curl -X POST "https://eyesapi.applitools.com/api/externals/github/servers/github.com/commit/${{ env.APPLITOOLS_BATCH_ID }}/${{ github.run_id }}/complete?apiKey=${{secrets.APPLITOOLS_API_KEY}}"

0 commit comments

Comments
 (0)