Skip to content

Commit

Permalink
Add GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-linaro committed Oct 23, 2020
1 parent 2df71e4 commit b37a78d
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .github-env-master
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
AWS_STATIC_SITE_PROFILE=morello-org-buildbot
AWS_STATIC_SITE_URL=production-morello-project-org
CF_DIST_ID_STATIC_LO=E2GWIYO8RAV1ZB
CLOUDFRONT_ADD_SECURITY_HEADERS_ARN=arn:aws:lambda:us-east-1:718845120493:function:cloudfront-add-security-headers-production:1
JEKYLL_ENV=production
SITE_URL=production.morello-project.org
15 changes: 15 additions & 0 deletions .github/workflows/closerequest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: ClosePullRequestAction

on:
pull_request_target:
types: [closed]
branches: [ main, master, develop ]

jobs:
close:
runs-on: self-hosted
steps:
- name: Initialise environment
run: cat ".github-env-$GITHUB_BASE_REF" >> $GITHUB_ENV
- name: Clean up
run: /srv/github-action-scripts/close-pr.sh
54 changes: 54 additions & 0 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: PullRequestAction

on:
pull_request_target:
branches: [ main, master, develop ]

jobs:
build:
runs-on: self-hosted
steps:
- name: Cancel previous runs
uses: n1hility/cancel-previous-runs@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Fetch git repository
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Initialise environment
run: cat ".github-env-$GITHUB_BASE_REF" >> $GITHUB_ENV

- run: env

- name: Initialise status
run: /srv/github-action-scripts/init-deploy-preview.sh
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Merge test branch
uses: linaro-its/merge-test-branch@v1

- name: Build site
run: /srv/github-action-scripts/build-jekyll-site.sh
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}

check-links:
needs: build
runs-on: self-hosted
steps:
- name: Initialise environment
run: cat ".github-env-$GITHUB_BASE_REF" >> $GITHUB_ENV

- name: Check links
run: /srv/github-action-scripts/check-links.sh

test-routing-rules:
needs: check-links
runs-on: self-hosted
steps:
- name: Check routing rules
run: /srv/github-action-scripts/test-routing-rules.sh
101 changes: 101 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: PushAction

on:
push:
branches: [ main, master, develop ]
workflow_dispatch:

jobs:
build:
runs-on: self-hosted
steps:
- name: Cancel previous runs
uses: n1hility/cancel-previous-runs@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Fetch git repository
uses: actions/checkout@v2

- name: Initialise environment
run: cat ".github-env-${GITHUB_REF##*/}" >> $GITHUB_ENV

- run: env

- name: Directory push/pop
uses: linaro-its/[email protected]
with:
cacheDirectory: /srv/site-builds
namedDirectory: ${{ env.SITE_URL }}

- name: Build site
run: /srv/github-action-scripts/build-jekyll-site.sh
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}

check-links:
needs: build
runs-on: self-hosted
steps:
- name: Initialise environment
run: cat ".github-env-${GITHUB_REF##*/}" >> $GITHUB_ENV

- name: Check links
run: /srv/github-action-scripts/check-links.sh /srv/site-builds/${{ env.SITE_URL }}

test-routing-rules:
needs: check-links
runs-on: self-hosted
steps:
- name: Check routing rules
run: /srv/github-action-scripts/test-routing-rules.sh

sync-to-s3-staging:
needs: test-routing-rules
runs-on: self-hosted
steps:
- name: Make staging directory
run: mkdir -p /srv/s3-staging/${{ env.SITE_URL }}

- name: Sync build to staging directory
run: rsync -crui /srv/site-builds/${{ env.SITE_URL }}/ /srv/s3-staging/${{ env.SITE_URL }} --delete

update-to-s3:
needs: sync-to-s3-staging
runs-on: self-hosted
steps:
- name: Initialise environment
run: cat ".github-env-${GITHUB_REF##*/}" >> $GITHUB_ENV

- name: Upload to S3
run: /srv/github-action-scripts/upload-to-s3-root.sh

set-up-lambda-redirect:
needs: update-to-s3
runs-on: self-hosted
steps:
- name: Initialise environment
run: cat ".github-env-${GITHUB_REF##*/}" >> $GITHUB_ENV

- name: Set up Lambda redirect
run: /srv/github-action-scripts/set-up-lambda-redirect.sh /srv/site-builds/${{ env.SITE_URL }}

set-up-security-headers:
needs: set-up-lambda-redirect
runs-on: self-hosted
steps:
- name: Initialise environment
run: cat ".github-env-${GITHUB_REF##*/}" >> $GITHUB_ENV

- name: Set up security headers
run: cd /srv/github-action-scripts && pipenv run python lambda-security-headers.py

invalidate-cloudfront:
needs: set-up-security-headers
runs-on: self-hosted
steps:
- name: Initialise environment
run: cat ".github-env-${GITHUB_REF##*/}" >> $GITHUB_ENV

- name: Invalidate CloudFront cache
run: /srv/github-action-scripts/invalidate-cloudfront.sh
10 changes: 6 additions & 4 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
build-site.sh @pcolmer @morancj
check-links.sh @pcolmer @morancj
CODEOWNERS @pcolmer @morancj
Gemfile @pcolmer @morancj
build-site.sh @pcolmer @kylekirkby
check-links.sh @pcolmer @kylekirkby
CODEOWNERS @pcolmer @kylekirkby
Gemfile @pcolmer @kylekirkby
.github-env-master @pcolmer @kylekirkby
.github/workflows @pcolmer @kylekirkby
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ To make it easier to contribute to the content, [Linaro](https://www.linaro.org)

To build the site:

```
```bash
cd <git repository directory>
./build-site.sh
```

To build the site and then serve it so that you can check your contribution appears:

```
```bash
cd <git repository directory>
JEKYLL_ACTION="serve" ./build-site.sh
```

To check that your contribution doesn't include any broken links:

```
```bash
cd <built web site directory>
../check-links.sh
```
Expand All @@ -39,4 +38,8 @@ The built web site directory will be `staging.morello-project.org` unless you se

For more information, please see the [build container wiki](https://github.com/linaro-its/jekyll-build-container/wiki) and the [link checker wiki](https://github.com/linaro-its/jekyll-link-checker/wiki).

*****
## Pull Requests

When a Pull Request is created, GitHub Actions are used to automatically build a test version of the proposed modified site and then check that any links in the pages are valid.

If there are any questions or problems with the GitHub Actions, please contact [Linaro IT Services](https://servicedesk.linaro.org/servicedesk/customer/portal/3/create/50).

0 comments on commit b37a78d

Please sign in to comment.