forked from alphagov/govuk-design-system
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request alphagov#1442 from alphagov/deploy-github-actions
Switch from Travis to Github Actions
- Loading branch information
Showing
9 changed files
with
116 additions
and
118 deletions.
There are no files selected for viewing
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,96 @@ | ||
name: CI Workflow | ||
|
||
on: [push, pull_request] | ||
|
||
# Separate build and deploy jobs so we can build all branches and pull requests | ||
# but only deploy from master | ||
jobs: | ||
build: | ||
name: Build & Test | ||
runs-on: ubuntu-latest | ||
env: | ||
ENVIRONMENT: production | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Read node version from .nvmrc | ||
id: nvm | ||
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)" | ||
|
||
- name: Setup node | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: "${{ steps.nvm.outputs.NVMRC }}" | ||
|
||
- name: Install dependencies | ||
run: npm install --no-optional | ||
|
||
- name: Build | ||
run: npm run build | ||
|
||
- name: Lint and test | ||
run: npm test -- --runInBand | ||
|
||
# Share data between the build and deploy jobs so we don't need to run `npm run build` again on deploy | ||
# Upload the deploy folder as an artifact so it can be downloaded and used in the deploy job | ||
- name: Upload artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: build | ||
path: deploy/** | ||
retention-days: 1 | ||
|
||
# Deploy the Design System to production when the master branch is changed | ||
# Github Actions is not involved in deploying PR or branch previews – these are handled by Netlify | ||
deploy: | ||
name: Deploy | ||
runs-on: ubuntu-latest | ||
needs: build | ||
if: ${{ github.ref == 'refs/heads/master' }} | ||
env: | ||
CF_API: "https://api.cloud.service.gov.uk" | ||
CF_ORG: "govuk-design-system" | ||
CF_SPACE: "design-system" | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Download build artifact | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: build | ||
|
||
- name: Install the CF CLI | ||
run: | | ||
wget https://s3-us-west-1.amazonaws.com/v7-cf-cli-releases/releases/v7.2.0/cf7-cli-installer_7.2.0_x86-64.deb | ||
sudo dpkg -i cf7-cli-installer_7.2.0_x86-64.deb | ||
- name: Authenticate | ||
env: | ||
# CF_USERNAME and CF_PASSWORD are used by the `cf auth` command to login | ||
# We use an environment variable instead of passing the details as options using -u / -p to reduce the risk of them being recorded in logs | ||
# https://cli.cloudfoundry.org/en-US/v6/auth.html | ||
CF_USERNAME: "[email protected]" | ||
CF_PASSWORD: ${{ secrets.CF_PASSWORD }} | ||
run: | | ||
echo "Logging into $CF_ORG/$CF_SPACE..." | ||
cf api "${CF_API}" | ||
cf auth | ||
cf target -o "${CF_ORG}" -s "${CF_SPACE}" | ||
# Parse app name from manifest to ensure it matches up | ||
- name: Fetch app name from manifest | ||
run: echo "APP_NAME=$(ruby -e "require 'yaml'; config = YAML.load_file('manifest.yml'); puts config['applications'][0]['name']")" >> $GITHUB_ENV | ||
|
||
- name: Cancel any existing running deploys to avoid conflict | ||
run: | | ||
echo "Cancelling any previous deployments in progress" | ||
cf cancel-deployment $APP_NAME || true | ||
- name: Deploy to PaaS | ||
# Deploy app and set up app healthcheck https://docs.cloudfoundry.org/devguide/deploy-apps/healthchecks.html | ||
run: | | ||
echo "Deploying $APP_NAME to $CF_ORG/$CF_SPACE..." | ||
cf push $APP_NAME --strategy rolling | ||
cf logout |
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
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -5,34 +5,33 @@ | |
The Design System is a static site which is generated by | ||
[Metalsmith](http://www.metalsmith.io/). | ||
|
||
When the master branch changes, [Travis][travis] will build the static site by | ||
When the master branch changes, [Github Actions][github-actions] will build the static site by | ||
running `npm run build`. As long as that succeeds, the contents of the deploy | ||
directory will then by uploaded to our application on | ||
[GOV.UK Platform as a Service][paas] (PaaS). GOV.UK PaaS uses the open source Cloud Foundry project and exposes parts of their API. | ||
|
||
We use nginx as a simple web server. | ||
|
||
## Travis | ||
## Github Actions | ||
|
||
### Configuration | ||
|
||
Travis is configured using the [.travis.yml](../../.travis.yml) config file. Travis | ||
will attempt to build the Design System, run the linter and run tests for every | ||
branch, but will only run the deploy step when on the master branch. | ||
The Github Actions CI workflow is configured in [.github/workflows/ci.yaml](../../.github/workflows/ci.yaml). | ||
It will attempt to build the Design System, run the linter and run tests for every branch, | ||
but will only run the deploy step when on the master branch. | ||
|
||
Configuration is done using [environment variables][travis-env]. Configuration | ||
which needs to remain secure is encrypted using `travis encrypt`. | ||
Most of the environment variables needed are set within each Github Action script. Any secrets can be viewed and changed within the Github UI (requires admin access). | ||
|
||
### Deployment | ||
|
||
Travis is deployed using [deploy-travis](bin/deploy-travis). | ||
The Github Actions deployment script is detailed in [.github/workflows/ci.yaml](../../.github/workflows/ci.yaml) | ||
|
||
We log into CloudFoundry using the configured environment variables. We then run a smoke test to make sure that the app built correctly. | ||
We log into CloudFoundry using the configured environment variables. Before deploying, we cancel any existing deployments to prevent conflicts. When deploying, we use healthchecks to check that the /__canary__ path returns | ||
a 200 response, which indicates that the app has been built successfully. | ||
|
||
## Hosting on GOV.UK Platform as a Service (PaaS) | ||
|
||
We deploy to the `govuk-design-system-origin` app using the | ||
[blue-green-deploy][bgd] plugin. | ||
We deploy to the `govuk-design-system-origin` app. | ||
|
||
This app exists within the `govuk-design-system` organisation and the | ||
`production` space, and is deployed by the `[email protected]` user, the | ||
|
@@ -115,10 +114,8 @@ trailing-slashed URLs, but decided against it because: | |
- other parts of GOV.UK's infrastructure (such as their mirroring) make | ||
assumptions based on the lack of a trailing slash and relative URLs. | ||
|
||
[travis]: https://travis-ci.org/alphagov/govuk-design-system | ||
[travis-env]: https://docs.travis-ci.com/user/environment-variables/ | ||
[github-actions]: https://github.com/alphagov/govuk-design-system/actions | ||
[paas]: https://www.cloud.service.gov.uk/ | ||
[bgd]: https://github.com/bluemixgaragelondon/cf-blue-green-deploy | ||
[nginx-bp]: https://github.com/cloudfoundry/nginx-buildpack | ||
[govuk-dns-config]: https://github.com/alphagov/govuk-dns-config/blob/master/service.gov.uk.yaml | ||
[govuk-dns]: https://github.com/alphagov/govuk-dns | ||
|
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
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