Skip to content
This repository has been archived by the owner on Sep 1, 2021. It is now read-only.

Add screenshots workflow #796

Merged
merged 1 commit into from
Oct 7, 2020
Merged

Add screenshots workflow #796

merged 1 commit into from
Oct 7, 2020

Conversation

jacobwinch
Copy link
Contributor

@jacobwinch jacobwinch commented Oct 7, 2020

Why are you doing this?

This PR adds functionality for automatically capturing screenshots from a running version of each pull-request branch and comparing them with screenshots captured from the main branch. It builds upon the work started in #684, which allows us to run the application within the GitHub Actions infrastructure.

During my original experiment I was planning to replace the PR deployment workflow with this new one, but I noticed that a few people are already using PR deployments in their current form (🎉). Perhaps it is useful to keep both as they have slightly different use-cases.

https://theguardian.atlassian.net/browse/LIVE-605

Changes

  • Add new workflow file

Screenshots

See below 🤞

@github-actions
Copy link

github-actions bot commented Oct 7, 2020

Before After

name: Screenshots

on:
push:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows us to collect a new baseline (or 'Before' screenshot) each time a new change is merged to main.

Copy link
Contributor Author

@jacobwinch jacobwinch Oct 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously we'll only know that works correctly for sure once this PR is merged! For the purposes of the example comment on this PR, the 'Before' screenshot was captured via this hack.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if the branch is main this runs up to and including the "Upload screenshot" step, but doesn't add the comments?

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of this code is duplicated between several workflow files, which is a pain. Unfortunately GitHub Actions doesn't provide a good way to share these steps between multiple workflows yet. See actions/runner#646 for more details.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wrote an action to combine these steps would that work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we could write our own action, or a small bash script.

Copy link
Contributor Author

@jacobwinch jacobwinch Oct 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a thing called a composite action, but it won't allow you to have the uses syntax (and therefore you can't simply reference other actions, like we do here)

- name: Take screenshot of apps-rendering
uses: "lannonbr/[email protected]"
with:
url: http://localhost:8080/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously we could capture a more interesting collection of screenshots here!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean a different page, or a list of pages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess taking screenshots of several different articles would help us to catch more problems?

env:
AWS_ACCESS_KEY_ID: ${{ secrets.CI_IMAGE_UPLOADER_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CI_IMAGE_UPLOADER_SECRET_ACCESS_KEY }}
- name: Prepare image urls
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all getting a bit ugly - we could write our own Javascript action (and store it within this repo) if this bothers people too much.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like a nice solution longer term, if we'd like to port this functionality to other projects.

Copy link
Contributor

@JamieB-gu JamieB-gu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! 🚀

env:
AWS_ACCESS_KEY_ID: ${{ secrets.CI_IMAGE_UPLOADER_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CI_IMAGE_UPLOADER_SECRET_ACCESS_KEY }}
- name: Prepare image urls
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like a nice solution longer term, if we'd like to port this functionality to other projects.

Comment on lines +51 to +52
echo "::set-output name=before::https://gu-mobile-pr-images.s3-eu-west-1.amazonaws.com/$MAIN_COMMIT_SHA/screenshot.png"
echo "::set-output name=after::https://gu-mobile-pr-images.s3-eu-west-1.amazonaws.com/${{ github.sha }}/screenshot.png"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are ::set-output and name=before:: special GH Actions syntax?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep - here is the documentation.

- name: Take screenshot of apps-rendering
uses: "lannonbr/[email protected]"
with:
url: http://localhost:8080/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean a different page, or a list of pages?

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wrote an action to combine these steps would that work?

name: Screenshots

on:
push:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if the branch is main this runs up to and including the "Upload screenshot" step, but doesn't add the comments?

@jacobwinch jacobwinch merged commit 78b6716 into main Oct 7, 2020
@jacobwinch jacobwinch deleted the jw-add-screenshots-action branch October 7, 2020 15:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants