-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Migrate Percy from CircleCI to Github Actions #1097
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Update Percy Baseline | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
snapshot: | ||
name: Take Percy snapshots | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout SCM | ||
uses: actions/checkout@v4 | ||
|
||
- uses: ./.github/workflows/percy-snapshot | ||
with: | ||
branch_name: main | ||
commitsh: ${{ github.sha }} | ||
percy_token_write: ${{ secrets.PERCY_TOKEN_WRITE }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
name: Percy Snapshot | ||
description: Builds storybook, captures example snapshots, & uploads them to Percy | ||
inputs: | ||
pr_number: | ||
required: false | ||
pastelcyborg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
description: Identifier of a pull request to associate with this Percy build. I.E. github.com/{repo}/pull/{pr_number} | ||
commitsh: | ||
required: true | ||
description: SHA signature of commit triggering the build | ||
branch_name: | ||
required: true | ||
description: Name of the branch that Percy is being run against | ||
percy_token_write: | ||
required: true | ||
description: Percy token with write access | ||
outputs: | ||
build_link: | ||
description: Link to the Percy build triggered by this workflow | ||
value: ${{ steps.percy_snapshot.outputs.build_link }} | ||
build_id: | ||
description: ID of the Percy build triggered by this workflow | ||
value: ${{ steps.percy_snapshot.outputs.build_id }} | ||
org_id: | ||
description: ID of the organization associated with the Percy build | ||
value: ${{ steps.percy_snapshot.outputs.org_id }} | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Install NodeJS | ||
uses: actions/[email protected] | ||
with: | ||
node-version: 20 | ||
|
||
# https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix | ||
- name: Install dependencies | ||
shell: bash | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get -y upgrade | ||
sudo apt-get -yq install gconf-service libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxss1 libxtst6 libappindicator1 libnss3 libasound2 libatk1.0-0 libc6 ca-certificates fonts-liberation lsb-release xdg-utils wget libgbm-dev | ||
yarn install | ||
|
||
- name: Take snapshots & upload to Percy | ||
shell: bash | ||
id: percy_snapshot | ||
env: | ||
PERCY_TOKEN: ${{ inputs.percy_token_write }} | ||
# This identifies the diff by name in the percy diffs list | ||
PERCY_BRANCH: ${{ inputs.branch_name }} | ||
PERCY_COMMIT: ${{ inputs.commitsh }} | ||
PERCY_CLIENT_ERROR_LOGS: false | ||
# If PR number is set & a Percy-GHA integration is set up, this allows Percy to set status on the PR | ||
PERCY_PULL_REQUEST: ${{ inputs.pr_number }} | ||
run: | | ||
set -e | ||
# Start a percy build and capture the stdout | ||
|
||
# Start a percy build and capture the stdout and stderr | ||
percy_output=$(yarn percy 2>&1) | ||
|
||
echo "$percy_output" | ||
|
||
# Fail if the Percy stdout contains "Build not created" | ||
if echo "$percy_output" | grep -q "Build not created"; then | ||
echo "Percy build not created." | ||
exit 1 | ||
else | ||
echo "Percy build created successfully" | ||
fi | ||
|
||
# Extract the build link from the stdout of the snapshot command | ||
build_link=$(echo "$percy_output" | sed -n 's/.*Finalized build #.*: \(https:\/\/percy.io\/[^ ]*\).*/\1/p') | ||
|
||
# Using '/' to split the $build_link, extract the organization and build identifiers | ||
org_id=$(echo "$build_link" | cut -d '/' -f 4) | ||
build_id=$(echo "$build_link" | cut -d '/' -f 7) | ||
|
||
echo "build_link=$build_link" >> $GITHUB_OUTPUT | ||
echo "org_id=$org_id" >> $GITHUB_OUTPUT | ||
echo "build_id=$build_id" >> $GITHUB_OUTPUT | ||
echo "Percy build created at $build_link" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: "Prepare Percy build" | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
copy_artifact: | ||
name: Copy changed files to GHA artifact | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
with: | ||
sparse-checkout: | | ||
src/ | ||
|
||
- name: Populate artifact directory | ||
run: | | ||
mkdir -p artifact | ||
cp -R src/ artifact/. | ||
|
||
# Archive the PR number associated with this workflow since it won't be available in the base workflow context | ||
# https://github.com/orgs/community/discussions/25220 | ||
- name: Archive PR data | ||
if: github.event_name=='pull_request' | ||
working-directory: artifact | ||
run: | | ||
echo ${{ github.event.number }} > pr_num.txt | ||
echo ${{ github.event.pull_request.head.sha }} > pr_head_sha.txt | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: "percy-testing-web-artifact" | ||
path: artifact/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: "Percy screenshots" | ||
|
||
on: | ||
workflow_run: | ||
workflows: | ||
- "Prepare Percy build" | ||
types: | ||
- completed | ||
|
||
jobs: | ||
upload: | ||
name: Build project with proposed changes & take Percy snapshots | ||
if: github.event.workflow_run.conclusion=='success' | ||
runs-on: ubuntu-latest | ||
outputs: | ||
pr_head_sha: ${{ steps.get_pr_data.outputs.sha }} | ||
pr_number: ${{ steps.get_pr_data.outputs.pr_number }} | ||
percy_build_link: ${{ steps.percy_snapshot.outputs.build_link }} | ||
percy_org_id: ${{ steps.percy_snapshot.outputs.org_id }} | ||
percy_build_id: ${{ steps.percy_snapshot.outputs.build_id }} | ||
steps: | ||
- name: Checkout SCM | ||
uses: actions/checkout@v4 | ||
|
||
- name: Remove SCM directories that will be replaced by artifact files | ||
run: rm -rf src/ | ||
|
||
- name: Download artifact from workflow run | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: "percy-testing-web-artifact" | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
repository: ${{ github.event.workflow_run.repository.full_name }} | ||
run-id: ${{ github.event.workflow_run.id }} | ||
|
||
- name: Get PR data | ||
if: github.event.workflow_run.event=='pull_request' | ||
id: get_pr_data | ||
run: | | ||
echo "sha=$(cat pr_head_sha.txt)" >> $GITHUB_OUTPUT | ||
echo "pr_number=$(cat pr_num.txt)" >> $GITHUB_OUTPUT | ||
|
||
- name: Take snapshots & upload to Percy | ||
id: percy_snapshot | ||
uses: "./.github/workflows/percy-snapshot" | ||
with: | ||
branch_name: "pull/${{ steps.get_pr_data.outputs.pr_number }}" | ||
pr_number: ${{ steps.get_pr_data.outputs.pr_number }} | ||
commitsh: ${{ steps.get_pr_data.outputs.sha }} | ||
percy_token_write: ${{ secrets.PERCY_TOKEN_WRITE }} | ||
|
||
# Add a check to the PR to show that screenshots were sent to Percy | ||
# https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#create-a-check-run | ||
apply_pr_check: | ||
name: Apply PR check | ||
needs: upload | ||
if: github.event.workflow_run.event=='pull_request' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Apply PR check | ||
id: create_check_run | ||
uses: octokit/[email protected] | ||
with: | ||
route: POST /repos/${{ github.repository }}/check-runs | ||
owner: octokit | ||
repo: request-action | ||
name: "percy_upload" | ||
head_sha: ${{ needs.upload.outputs.pr_head_sha }} | ||
status: completed | ||
conclusion: success | ||
details_url: ${{ needs.upload.outputs.percy_build_link }} | ||
output: | | ||
title: "Percy build" | ||
summary: "Percy build #${{ needs.upload.outputs.percy_build_id }} created" | ||
text: "Percy build was created at ${{ needs.upload.outputs.percy_build_link }}" | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: since
name
is often used essentially as a variable, could we name them like variables? If an English description of the job is needed, thedescription
key should probably be usedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pastelcyborg I'm not aware of a "description" key in the official GHA workflow syntax:
https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
Would you still prefer names be changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmmm,
description
is mentioned a number of times in the docs, but it's entirely possible I just don't know Actions/Workflows well enough to understand when it is and isn't available. I trust your judgment - if it's not available, the current names are fineThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I'm aware, often the job key itself (from the YAML structure) is used as an identifier for use in other jobs, such as here:
https://github.com/canonical/vanilla-framework/blob/f82114a926a3a43dcae059a034e8e67a6eab962a/.github/workflows/pr-percy-snapshots.yml#L68
Then the job name is used for displaying in a "pretty" way on GH actions workflow pages, etc