-
Notifications
You must be signed in to change notification settings - Fork 0
190 lines (164 loc) · 6.36 KB
/
pages-gh.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# Sample workflow for building and deploying a Hugo site to GitHub Pages
name: Deploy Hugo site to Pages and build docker image [GitHub.com]
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
SERVICE: landing
# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true
# Default to bash
defaults:
run:
shell: bash
jobs:
generate-timestamp:
runs-on: ubuntu-latest
steps:
- name: Set TIMESTAMP
id: date
run: |
export DATE=$(date +'%Y%m%d-%H%M%S')
echo "TIMESTAMP=$DATE" >> $GITHUB_ENV
outputs:
TIMESTAMP: ${{ env.TIMESTAMP }}
configure-pages:
runs-on: ubuntu-latest
steps:
- name: Setup Pages
id: pages
uses: actions/configure-pages@v2
outputs:
base_url: ${{ steps.pages.outputs.base_url }}
# Build job
build-website:
needs:
- configure-pages
runs-on: ubuntu-latest
container:
image: peaceiris/hugo
env:
HUGO_VERSION: latest # 0.126.1
HUGO_FORMS: ${{ vars.HUGO_FORMS }}
HUGO_GOOGLEANALYTICS: ${{ vars.HUGO_GOOGLEANALYTICS }}
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
steps:
# GH Actions
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: ${{ env.HUGO_VERSION }}
extended: true
- name: Pre-Build ls
run: |
ls -lah
echo "${{ needs.generate-timestamp.outputs.TIMESTAMP }}" from env
echo "${{ needs.configure-pages.outputs.base_url }}/" from env
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true # Fetch Hugo themes (true OR recursive) # failing on ubuntu container
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
# set-safe-directory: '/__w/coastal-science.github.io/coastal-science.github.io'
- name: Set safe directory workaround
run: |
git config --global --add safe.directory /__w/coastal-science.github.io/coastal-science.github.io
- name: Build with Hugo
env:
# For maximum backward compatibility with Hugo modules
HUGO_ENVIRONMENT: production
HUGO_ENV: production
run: |
hugo \
--gc \
--buildDrafts \
--minify \
--baseURL "${{ needs.configure-pages.outputs.base_url }}/"
- name: Post-Build ls
run: ls -lah public/
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public
# Deployment job
deploy-gh-pages:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: write
id-token: write
pages: write
runs-on: ubuntu-latest
needs: build-website
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
# Create and publish a docker image
build_and_push_image:
if: false
needs:
- generate-timestamp
- build-website
runs-on: ubuntu-latest
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: docker.github.sfu.ca #ghcr.io
IMAGE_NAME: ${{ github.repository }}
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
packages: write
outputs:
tags: ${{ steps.meta.outputs.tags }}
steps:
# - name: Checkout repository
# uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ env.SERVICE }}
labels: |
org.opencontainers.image.version=${{ needs.generate-timestamp.outputs.TIMESTAMP }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# Cleanup workspace on the runner
cleanup:
# if: ${{ always() }}
needs:
- build-website
- deploy-gh-pages
- build_and_push_image
runs-on: ubuntu-latest
steps:
- name: Current workspace
run: du -shc ${GITHUB_WORKSPACE}
- name: Clean Up Docker Images
run: docker rmi -f $(docker images '${{ needs.build_and_push_image.outputs.tags }}' -a -q)
- name: Clean Up Workspace
run: rm -rf ${GITHUB_WORKSPACE}