Automated actions configured through GitHub Actions
This documentation explains how our GitHub actions integrate themselves with the Zeit platform
Stuff to read if you're not familiar with GitHub Actions
Most useful documentation links:
- https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#about-yaml-syntax-for-workflows
- https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#on
- https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idneeds
- https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idruns-on
- https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
List of necessary requirements for the
Github Actions <> Zeit
to work properly.
Those secrets must be added on Github settings page, such as https://github.com/UnlyEd/next-right-now/settings/secrets
-
GITHUB_CI_PR_COMMENT
: Allows to post comments on GitHub Pull Request - See https://github.com/settings/tokens GitHub "personal access token" from your personal account with the following permission scopes:repo
(all)user
read:user
user:email
workflow
-
ZEIT_TOKEN
: Allows to trigger deployments - See https://zeit.co/account/tokens Zeit personal token
We use two different stages. Each stage is meant to use a different configuration.
staging (see deploy-zeit-staging
):
Every pushed commit, (except those made on master
) automatically starts a new Zeit deployment, using the related staging configuration file.
You can choose which client you deploy by changing the symbolic link now.json
file.
production (see deploy-zeit-production
):
Commits pushed to the master
branch will automatically deploy the now-production.json
configuration.
N.B: Those events are triggered by pushed commit, but also merged branches.
The same workflow is used for both stages. The main difference is the trigger.
A
production
deployment is triggered by any change in themaster
branch, while astaging
deployment is triggered by any change that is not on themaster
branch.
Jobs workflow:
- Installing Node.js and npm dependencies, by specifying Node version
- Deploy code:
- We checkout to the last branch commit, documentation here
- Run 2e2 tests:
- We need to checkout again (because the code is not persistent)
- We ask to Zeit api for the last deployment data, retrieve the url and then set it as environment variable as
ZEIT_DEPLOYMENT_URL
(to be able to use it afterwards) - We use default action provided by cypress (documentation here):
- wait-on: Allows us to wait before starting tests. It ping the endpoint until it's up, with a timeout of 60 seconds per default.
- config-file: We need to specify a config file because cypress is looking for cypress.json in the main folder.
The config file itself doesn't matter because we will override most settings anyway. We just need
projectId
to run the tests. - config: Overrides some default config, like the
baseUrl
in particular (we use theZEIT_DEPLOYMENT_URL
instead)
- We upload artifacts on tests failure, more documentation here
- actions/setup-node@v1: Setup node.js and install dependencies
- actions/checkout@v1: Checkout to last commit to retrieve code
- cypress-io/github-action@v1: Run Cypress tests
- actions/upload-artifact@v1: Upload artifacts to Github
- jq: JSON parser for bash
- tr: Bash editor, used to remove characters
- echo "::set-env name=key::value": Set env variable for all others jobs