Skip to content

Commit

Permalink
Merge pull request #1102 from chromaui/cody/ci-cd-test
Browse files Browse the repository at this point in the history
Setup workflow for PR checks
  • Loading branch information
codykaup authored Oct 18, 2024
2 parents b4170a8 + a2d05ba commit 9ae5118
Show file tree
Hide file tree
Showing 16 changed files with 197 additions and 22 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/chromatic-prod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Chromatic
on: push

on:
workflow_call:
secrets:
CHROMATIC_PROJECT_TOKEN:
required: true

permissions:
contents: read
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Lint and Test
on: push

on:
workflow_call:
secrets:
CODACY_PROJECT_TOKEN:
required: true

permissions:
contents: read
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/package-size.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: Chromatic Package Size

on:
pull_request:
branches: [main]
types: [opened, synchronize]
workflow_call:
secrets:
UPSTASH_REDIS_REST_URL:
required: true
UPSTASH_API_KEY:
required: true

permissions:
contents: read
Expand Down
96 changes: 96 additions & 0 deletions .github/workflows/pull-request-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Test PR

on:
merge_group:
types:
- checks_requested
pull_request:
types:
- opened
- synchronize
- reopened

permissions:
contents: read

jobs:
package-size:
uses: ./.github/workflows/package-size.yml
permissions:
contents: read
issues: write
pull-requests: write
secrets:
UPSTASH_REDIS_REST_URL: ${{ secrets.UPSTASH_REDIS_REST_URL }}
UPSTASH_API_KEY: ${{ secrets.UPSTASH_API_KEY }}

lint-and-test:
uses: ./.github/workflows/lint-and-test.yml
secrets:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}

chromatic:
uses: ./.github/workflows/chromatic-prod.yml
needs: lint-and-test
secrets:
CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}

smoke-test-action:
uses: ./.github/workflows/smoke-test-action.yml
needs: lint-and-test
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN: ${{ secrets.SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN }}

smoke-test-node-api:
uses: ./.github/workflows/smoke-test-node-api.yml
needs: lint-and-test
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN: ${{ secrets.SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN }}

smoke-test-node-18:
uses: ./.github/workflows/smoke-test-node18.yml
needs: lint-and-test
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN: ${{ secrets.SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN }}

smoke-test-node-20:
uses: ./.github/workflows/smoke-test-node20.yml
needs: lint-and-test
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN: ${{ secrets.SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN }}

smoke-test-npx:
uses: ./.github/workflows/smoke-test-npx.yml
needs: lint-and-test
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN: ${{ secrets.SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN }}

smoke-test-windows:
uses: ./.github/workflows/smoke-test-windows.yml
needs: lint-and-test
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN: ${{ secrets.SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN }}

smoke-test-yarn:
uses: ./.github/workflows/smoke-test-yarn.yml
needs: lint-and-test
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN: ${{ secrets.SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN }}

smoke-test-yarn-berry:
uses: ./.github/workflows/smoke-test-yarn-berry.yml
needs: lint-and-test
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN: ${{ secrets.SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN }}

smoke-test-yarn-canary:
uses: ./.github/workflows/smoke-test-yarn-canary.yml
needs: lint-and-test
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN: ${{ secrets.SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN }}

smoke-test-yarn-classic:
uses: ./.github/workflows/smoke-test-yarn-classic.yml
needs: lint-and-test
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN: ${{ secrets.SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN }}
Empty file modified .github/workflows/smoke-test-action-next.yml
100755 → 100644
Empty file.
6 changes: 5 additions & 1 deletion .github/workflows/smoke-test-action.yml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Smoke test via action
on: push
on:
workflow_call:
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN:
required: true

permissions:
contents: read
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/smoke-test-node-api.yml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Smoke test via node api
on: push

on:
workflow_call:
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN:
required: true

permissions:
contents: read
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/smoke-test-node18.yml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Smoke test via Node 18
on: push

on:
workflow_call:
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN:
required: true

permissions:
contents: read
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/smoke-test-node20.yml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Smoke test via Node 20
on: push

on:
workflow_call:
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN:
required: true

permissions:
contents: read
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/smoke-test-npx.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
name: Smoke test via npx
on: push

on:
workflow_call:
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN:
required: true

permissions:
contents: read

jobs:
chromatic:
self-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/smoke-test-windows.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
name: Smoke test via yarn on Windows
on: push

on:
workflow_call:
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN:
required: true

permissions:
contents: read

jobs:
chromatic:
self-test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/smoke-test-yarn-berry.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
name: Smoke test via yarn berry
on: push

on:
workflow_call:
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN:
required: true

permissions:
contents: read

jobs:
chromatic:
self-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/smoke-test-yarn-canary.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
name: Smoke test via yarn canary
on: push

on:
workflow_call:
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN:
required: true

permissions:
contents: read

jobs:
chromatic:
self-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/smoke-test-yarn-classic.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
name: Smoke test via yarn classic
on: push

on:
workflow_call:
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN:
required: true

permissions:
contents: read

jobs:
chromatic:
self-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/smoke-test-yarn.yml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Smoke test via yarn
on: push

on:
workflow_call:
secrets:
SMOKE_TESTS_CHROMATIC_PROJECT_TOKEN:
required: true

permissions:
contents: read
Expand Down
20 changes: 18 additions & 2 deletions node-src/git/getCommitAndBranch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const commitInfo = {

describe('getCommitAndBranch', () => {
it('returns commit and branch info', async () => {
process.env.GITHUB_EVENT_NAME = 'push';

const info = await getCommitAndBranch(ctx);
expect(info).toMatchObject({
branch: 'main',
Expand All @@ -62,6 +64,8 @@ describe('getCommitAndBranch', () => {
});

it('retrieves CI context', async () => {
process.env.GITHUB_EVENT_NAME = 'push';

envCi.mockReturnValue({
isCi: true,
service: 'ci-service',
Expand All @@ -84,6 +88,8 @@ describe('getCommitAndBranch', () => {
});

it('prefers prBranch over ciBranch', async () => {
process.env.GITHUB_EVENT_NAME = 'push';

envCi.mockReturnValue({
branch: 'ci-branch',
prBranch: 'ci-pr-branch',
Expand All @@ -94,9 +100,11 @@ describe('getCommitAndBranch', () => {
});

it('removes origin/ prefix in branch name', async () => {
getBranch.mockResolvedValue('origin/master');
process.env.GITHUB_EVENT_NAME = 'push';

getBranch.mockResolvedValue('origin/main');
const info = await getCommitAndBranch(ctx);
expect(info).toMatchObject({ branch: 'master' });
expect(info).toMatchObject({ branch: 'main' });
});

it('throws when there is only one commit, CI', async () => {
Expand All @@ -114,23 +122,31 @@ describe('getCommitAndBranch', () => {

describe('with branchName', () => {
it('uses provided branchName as branch', async () => {
process.env.GITHUB_EVENT_NAME = 'push';

const info = await getCommitAndBranch(ctx, { branchName: 'foobar' });
expect(info).toMatchObject({ branch: 'foobar' });
});

it('does not remove origin/ prefix in branch name', async () => {
process.env.GITHUB_EVENT_NAME = 'push';

const info = await getCommitAndBranch(ctx, { branchName: 'origin/foobar' });
expect(info).toMatchObject({ branch: 'origin/foobar' });
});
});

describe('with patchBaseRef', () => {
it('uses provided patchBaseRef as branch', async () => {
process.env.GITHUB_EVENT_NAME = 'push';

const info = await getCommitAndBranch(ctx, { patchBaseRef: 'foobar' });
expect(info).toMatchObject({ branch: 'foobar' });
});

it('prefers branchName over patchBaseRef', async () => {
process.env.GITHUB_EVENT_NAME = 'push';

const info = await getCommitAndBranch(ctx, { branchName: 'foo', patchBaseRef: 'bar' });
expect(info).toMatchObject({ branch: 'foo' });
});
Expand Down

0 comments on commit 9ae5118

Please sign in to comment.