Skip to content

Commit

Permalink
fix(chromatic): revert comment-based trigger (#1443)
Browse files Browse the repository at this point in the history
* fix(chromatic): revert comment-based trigger

* Add missing environment variable

* Fix condition to run Chromatic build

* Combine to single job due to context availability
  • Loading branch information
dcshzj authored Aug 23, 2023
1 parent 0109b46 commit e4d09d4
Showing 1 changed file with 14 additions and 93 deletions.
107 changes: 14 additions & 93 deletions .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,27 @@
name: "Chromatic"

# Event for the workflow
on:
issue_comment:
types: [created, edited]

push:
branches:
- develop
on: push

env:
# The full comment text to match to trigger this workflow
ISOMER_TRIGGER_COMMENT: "!run-chromatic"
# The slug for the Isomer core team
ISOMER_CORE_TEAM_SLUG: core
# Use GitHub Token
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
# Required for the chromatic action
REACT_APP_BACKEND_URL: "https://cms-api.isomer.gov.sg/v1"

# List of jobs
jobs:
changes:
chromatic-deployment:
# Operating System
runs-on: ubuntu-latest
# Set job outputs to values from filter step
outputs:
frontend: ${{ steps.filter.outputs.frontend }}
# Only run if the user is not a bot and there are changes
if: ${{ !endsWith(github.actor , 'bot') }}
environment: staging
# Job steps
steps:
- name: Checkout repository branch (PR comment)
if: ${{ github.event_name == 'issue_comment' && github.event.issue.pull_request }}
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
ref: refs/pull/${{ github.event.issue.number }}/head

- name: Checkout repository branch (push)
if: ${{ github.event_name == 'push' }}
uses: actions/checkout@v3
fetch-depth: 0 # 👈 Required to retrieve git history

- name: Check for changes
uses: dorny/paths-filter@v2
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
Expand All @@ -49,88 +32,26 @@ jobs:
- 'src/theme/**'
- 'src/styles/**'
chromatic-deployment:
# Operating System
runs-on: ubuntu-latest
# Only run if the user is not a bot and there are changes
if: ${{!endsWith(github.actor , 'bot')}} && steps.filter.outputs.frontend == 'true'
environment: staging
# Job steps
steps:
# Determine if the PR comment should trigger the Chromatic build
- name: Check if user is part of Isomer core team
if: ${{ github.event_name == 'issue_comment' && github.event.issue.pull_request }}
uses: tspascoal/get-user-teams-membership@v1
id: checkUserMember
with:
username: ${{ github.actor }}
team: ${{ env.ISOMER_CORE_TEAM_SLUG }}
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} # requires read:org

- name: Check for trigger words (in PR comment)
if: ${{ github.event_name == 'issue_comment' && github.event.issue.pull_request }}
uses: khan/[email protected]
id: check
with:
trigger: "${{ env.ISOMER_TRIGGER_COMMENT }}"
prefix_only: "true"
reaction: "+1"

- name: Set environment variable to run Chromatic build
if: ${{ steps.check.outputs.triggered == 'true' && (github.event_name == 'push' || (github.event_name == 'issue_comment' && github.event.issue.pull_request && steps.checkUserMember.outputs.isTeamMember == 'true')) }}
run: echo "ISOMER_RUN_CHROMATIC_BUILD=true" >> $GITHUB_ENV

- name: Checkout repository (pull request)
if: ${{ env.ISOMER_RUN_CHROMATIC_BUILD == 'true' && github.event_name == 'issue_comment' }}
uses: actions/checkout@v3
with:
ref: refs/pull/${{ github.event.issue.number }}/head
fetch-depth: 0 # 👈 Required to retrieve git history

- name: Checkout repository (push)
if: ${{ env.ISOMER_RUN_CHROMATIC_BUILD == 'true' && github.event_name == 'push' }}
uses: actions/checkout@v3
with:
fetch-depth: 0 # 👈 Required to retrieve git history

# This extra step is not in the original chromatic workflow.
# This is to pin the version of node (18.x) used.
- name: Setup Node.js
if: ${{ env.ISOMER_RUN_CHROMATIC_BUILD == 'true' }}
if: ${{ steps.filter.outputs.frontend == 'true' }}
uses: actions/setup-node@v3
with:
node-version: "18.x"
cache: "npm"

- name: Install dependencies
if: ${{ env.ISOMER_RUN_CHROMATIC_BUILD == 'true' }}
if: ${{ steps.filter.outputs.frontend == 'true' }}
run: npm ci

- name: Get pull request information (for pull requests)
if: ${{ env.ISOMER_RUN_CHROMATIC_BUILD == 'true' && github.event_name == 'issue_comment' }}
uses: octokit/[email protected]
id: get_pull_request
with:
route: GET /repos/{repository}/pulls/{pull_number}
repository: ${{ github.repository }} # isomerpages/isomercms-frontend
pull_number: ${{ github.event.issue.number }}

- name: Save branch name as environment variable (for pull requests)
if: ${{ env.ISOMER_RUN_CHROMATIC_BUILD == 'true' && github.event_name == 'issue_comment' }}
run: echo "ISOMER_BRANCH_NAME=${{ fromJSON(steps.get_pull_request.outputs.data).head.ref }}" >> $GITHUB_ENV

- name: Save branch name as environment variable (for push)
if: ${{ env.ISOMER_RUN_CHROMATIC_BUILD == 'true' && github.event_name == 'push' }}
run: echo "ISOMER_BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_ENV

# 👇 Adds Chromatic as a step in the workflow
# 👇 Adds Chromatic as a step in the workflow
- name: Publish to Chromatic
if: ${{ env.ISOMER_RUN_CHROMATIC_BUILD == 'true' }}
if: ${{ steps.filter.outputs.frontend == 'true' }}
uses: chromaui/action@v1
# Chromatic GitHub Action options
with:
token: ${{ secrets.GITHUB_TOKEN }}
# 👇 Chromatic projectToken, refer to the manage page to obtain it.
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
onlyChanged: true
branchName: ${{ env.ISOMER_BRANCH_NAME }}

0 comments on commit e4d09d4

Please sign in to comment.