Skip to content

Commit 4bc562a

Browse files
committed
simplify deployment actions
1 parent b6dd881 commit 4bc562a

File tree

2 files changed

+26
-74
lines changed

2 files changed

+26
-74
lines changed

.github/workflows/deployment.yml

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,26 @@ jobs:
1010
name: Deploy to GitHub Pages
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
14-
with:
15-
path: ./repo
16-
17-
- name: Set up Docker Buildx
18-
uses: docker/setup-buildx-action@v1
19-
20-
- name: Build and push
21-
uses: docker/build-push-action@v2
22-
with:
23-
context: ./repo
24-
file: ./repo/Dockerfile
25-
push: false
26-
load: true
27-
tags: operating-systems-jekyll:latest
28-
cache-from: type=gha
29-
cache-to: type=gha
13+
- uses: actions/checkout@v3
3014

31-
- name: GitHub-specific config
15+
- name: Build Jekyll site
3216
run: |
33-
cd repo
17+
# GitHub-specific config
3418
echo "url: https://${{ github.repository_owner }}.github.io" >> _config.yaml
3519
echo "baseurl: /operating-systems" >> _config.yaml
3620
37-
- name: Load image
38-
run: |
39-
mkdir output
40-
docker image list
41-
docker run -v $GITHUB_WORKSPACE/output:/usr/src/app/_site \
42-
-v $GITHUB_WORKSPACE/repo:/usr/src/app operating-systems-jekyll:latest \
43-
bundle exec jekyll build
21+
# Build Docker image for Jekyll
22+
docker build -t jekyll-image .
23+
24+
# Build Jekyll site
25+
docker run --rm \
26+
-v ${{ github.workspace }}:/usr/src/app
27+
jekyll-image bundle exec jekyll build
4428
45-
# Popular action to deploy to GitHub Pages:
46-
# Docs: https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-docusaurus
4729
- name: Deploy to GitHub Pages
4830
uses: peaceiris/actions-gh-pages@v3
4931
with:
5032
github_token: ${{ secrets.GITHUB_TOKEN }}
51-
# Build output to publish to the `gh-pages` branch:
52-
publish_dir: ./output
53-
# The following lines assign commit authorship to the official
54-
# GH-Actions bot for deploys to `gh-pages` branch:
55-
# https://github.com/actions/checkout/issues/13#issuecomment-724415212
56-
# The GH actions bot is used by default if you didn't specify the two fields.
57-
# You can swap them out with your own user credentials.
58-
user_name: 'github-actions[bot]'
59-
user_email: 'github-actions[bot]@users.noreply.github.com'
33+
publish_dir: _site
6034
publish_branch: gh-pages
6135
enable_jekyll: true

.github/workflows/pr-deployment.yml

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,74 +16,52 @@ jobs:
1616
steps:
1717
- name: Set Deployment ID
1818
run: |
19-
# Tag manual trigger with "manual-trigger"
20-
# Tag PR trigger with PR number
19+
# Use PR number for PR trigger and commit SHA for manual trigger
2120
if [[ -z "${{ github.event.pull_request.number }}" ]]; then
22-
echo "DEPLOYMENT_ID=manual-trigger" >> $GITHUB_ENV
21+
echo "DEPLOYMENT_ID=trigger-${GITHUB_SHA::7}" >> $GITHUB_ENV
2322
else
2423
echo "DEPLOYMENT_ID=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
2524
fi
2625
echo "DEPLOYMENT_ID=${{ env.DEPLOYMENT_ID }}"
2726
2827
- uses: actions/checkout@v3
2928
with:
30-
path: ./repo
3129
repository: ${{ github.event.pull_request.head.repo.full_name }}
3230
ref: ${{ github.head_ref }}
3331

34-
- name: Set up Docker Buildx
35-
uses: docker/setup-buildx-action@v1
36-
37-
- name: Build and push
38-
uses: docker/build-push-action@v3
39-
with:
40-
context: ./repo
41-
file: ./repo/Dockerfile
42-
push: false
43-
load: true
44-
tags: operating-systems-${{ env.DEPLOYMENT_ID }}:latest
45-
cache-from: type=gha
46-
cache-to: type=gha
47-
48-
- name: GitHub-specific config
32+
- name: Build Jekyll site
4933
run: |
50-
cd repo
34+
# GitHub-specific config
5135
echo "url: https://${{ github.repository_owner }}.github.io" >> _config.yaml
5236
echo "baseurl: /operating-systems/${{ env.DEPLOYMENT_ID }}" >> _config.yaml
5337
54-
- name: Load Image
55-
run: |
56-
mkdir -p ${{ env.DEPLOYMENT_ID }}
57-
docker image list
58-
docker run -v $GITHUB_WORKSPACE/${{ env.DEPLOYMENT_ID }}:/usr/src/app/_site \
59-
-v $GITHUB_WORKSPACE/repo:/usr/src/app operating-systems-${{ env.DEPLOYMENT_ID }}:latest \
60-
bundle exec jekyll build
61-
38+
# Build Docker image for Jekyll
39+
docker build -t jekyll-site .
40+
41+
# Build Jekyll site
42+
docker run --rm \
43+
-v ${{ github.workspace }}:/usr/src/app/ \
44+
jekyll-site bundle exec jekyll build
45+
6246
# Popular action to deploy to GitHub Pages:
6347
# Docs: https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-docusaurus
6448
- name: Deploy to GitHub Pages
6549
uses: peaceiris/actions-gh-pages@v3
6650
with:
6751
github_token: ${{ secrets.GITHUB_TOKEN }}
68-
# Build output to publish to the `gh-pages-pr` branch:
69-
publish_dir: ./${{ env.DEPLOYMENT_ID }}
52+
publish_dir: _site
7053
destination_dir: ${{ env.DEPLOYMENT_ID }}
71-
# The following lines assign commit authorship to the official
72-
# GH-Actions bot for deploys to `gh-pages` branch:
73-
# https://github.com/actions/checkout/issues/13#issuecomment-724415212
74-
# The GH actions bot is used by default if you didn't specify the two fields.
75-
# You can swap them out with your own user credentials.
7654
publish_branch: gh-pages
7755
enable_jekyll: true
7856

7957
- name: Add Comment to PR
80-
if: ${{ env.DEPLOYMENT_ID != 'manual-trigger' }}
58+
if: ${{ !startsWith(env.DEPLOYMENT_ID, 'trigger-') }}
8159
uses: thollander/actions-comment-pull-request@v2
8260
with:
8361
message: |
8462
Published at https://${{ github.repository_owner }}.github.io/operating-systems/${{ env.DEPLOYMENT_ID }}/
8563
8664
- name: Output Deployment URL
87-
if: ${{ env.DEPLOYMENT_ID == 'manual-trigger' }}
65+
if: ${{ startsWith(env.DEPLOYMENT_ID, 'trigger-') }}
8866
run: |
8967
echo "The deployment is available at https://${{ github.repository_owner }}.github.io/operating-systems/${{ env.DEPLOYMENT_ID }}/"

0 commit comments

Comments
 (0)