-
Notifications
You must be signed in to change notification settings - Fork 41
118 lines (108 loc) · 3.96 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: ruby/setup-ruby@v1
with:
ruby-version: "2.7"
bundler-cache: true
- uses: actions/setup-node@v2
with:
node-version: "14"
cache: yarn
cache-dependency-path: "**/yarn.lock"
# Yarn dependencies
- name: Yarn Install
run: yarn install
# Build
- name: Set production DEPLOY_ENV
if: github.ref == 'refs/heads/main'
run: echo "DEPLOY_ENV=production" >> $GITHUB_ENV
- name: Set staging DEPLOY_ENV
if: github.ref != 'refs/heads/main'
run: echo "DEPLOY_ENV=staging" >> $GITHUB_ENV
- name: Build
env:
DOCS_API_KEY: ${{ secrets.DOCS_API_KEY }}
run: bundle exec middleman build --clean --verbose --environment=${{ env.DEPLOY_ENV }}
# Lint
- name: Lint
run: bundle exec rake lint
# Artifact
- uses: actions/upload-artifact@v1
if: success() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging')
with:
name: build
path: ./build
# Push production builds to "build-history" branch to maintain history of
# built and deployed versions.
- name: Commit Build History
if: success() && github.ref == 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: yarn run gh-pages --dist ./build/ --branch build-history --user "$GITHUB_ACTOR <[email protected]>" --repo "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
deploy:
if: success() && github.repository_owner == 'NREL' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging')
needs: build
runs-on: ubuntu-latest
container:
image: rclone/rclone:1.57.0
steps:
# Deploy to S3 bucket.
- uses: actions/download-artifact@v1
with:
name: build
path: ./build
- name: Set production S3_DEST
if: github.ref == 'refs/heads/main'
run: echo "S3_DEST=:s3,env_auth=true:${{ secrets.PRODUCTION_BUCKET_NAME }}/public/production/" >> $GITHUB_ENV
- name: Set staging S3_DEST
if: github.ref != 'refs/heads/main'
run: echo "S3_DEST=:s3,env_auth=true:${{ secrets.STAGING_BUCKET_NAME }}/public/staging/" >> $GITHUB_ENV
- name: Deploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
run: |
# Sync all cache-busted assets with long cache-control expirations.
rclone \
copy \
--verbose \
--checksum \
--no-update-modtime \
--s3-no-check-bucket \
--s3-no-head \
--header-upload "Cache-Control: public, max-age=31536000, immutable" \
--include "/assets/**" \
./build/ \
"$S3_DEST"
# Sync the remaining files, disallowing caching on those.
rclone \
copy \
--verbose \
--checksum \
--no-update-modtime \
--s3-no-check-bucket \
--s3-no-head \
--header-upload "Cache-Control: no-cache, max-age=0, must-revalidate" \
./build/ \
"$S3_DEST"
# Run the sync one more time to delete old files. Keep old asset
# files around, so that if old HTML pages continue to load for a few
# minutes, they can still load older assets.
rclone \
sync \
--verbose \
--checksum \
--no-update-modtime \
--s3-no-check-bucket \
--s3-no-head \
--exclude "/assets/**" \
./build/ \
"$S3_DEST"