Skip to content

Commit 9dbd791

Browse files
authored
Release v2.0.0 (#10)
Changes for peaceiris/actions-gh-pages * update: yaml example of GitHub Actions v2 settings for MkDocs, close #8 * revert: support ACTIONS_DEPLOY_KEY (ssh deploy) again * upgrade: Hugo to v0.58.0 at example yaml * remove: steps if statement from example yaml, close #12 Changes for this repository * gha: add lint job (shellcheck and hadolint) * gha: remove tag filter * gha: remove steps if statement, close #12 * gha: add action.yml * fix: FUNDING.yml
1 parent 500440b commit 9dbd791

File tree

6 files changed

+142
-65
lines changed

6 files changed

+142
-65
lines changed

.github/workflows/docker-image-ci.yml

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ on:
44
push:
55
branches:
66
- master
7-
tags:
8-
- invalid-tag
7+
- 'release-v*'
98

109
jobs:
1110
test:
@@ -15,19 +14,34 @@ jobs:
1514
- uses: actions/checkout@master
1615

1716
- name: build
18-
if: github.event.deleted == false
1917
env:
2018
DOCKER_IMAGE: docker.pkg.github.com/${{ github.repository }}/action:latest
2119
run: |
2220
docker build . --file Dockerfile --tag ${DOCKER_IMAGE} ||
2321
(echo -e "\e[31m[${GITHUB_WORKFLOW}] failed to build\e[m" && exit 1)
2422
25-
- name: push latest image
26-
if: success() && endsWith(github.ref, 'master')
27-
env:
28-
DOCKER_IMAGE: docker.pkg.github.com/${{ github.repository }}/action:latest
29-
PKG_GITHUB_TOKEN: ${{ secrets.PKG_GITHUB_TOKEN }}
23+
# - name: push latest image
24+
# if: endsWith(github.ref, 'master')
25+
# env:
26+
# DOCKER_IMAGE: docker.pkg.github.com/${{ github.repository }}/action:latest
27+
# PKG_GITHUB_TOKEN: ${{ secrets.PKG_GITHUB_TOKEN }}
28+
# run: |
29+
# echo ${PKG_GITHUB_TOKEN} | docker login docker.pkg.github.com -u ${GITHUB_ACTOR} --password-stdin &&
30+
# docker push ${DOCKER_IMAGE} &&
31+
# docker logout
32+
33+
shellcheck:
34+
runs-on: ubuntu-18.04
35+
steps:
36+
- uses: actions/checkout@master
37+
- name: shellcheck
38+
run: shellcheck ./entrypoint.sh
39+
40+
hadolint:
41+
runs-on: macOS-10.14
42+
steps:
43+
- uses: actions/checkout@master
44+
- name: hadolint
3045
run: |
31-
echo ${PKG_GITHUB_TOKEN} | docker login docker.pkg.github.com -u ${GITHUB_ACTOR} --password-stdin &&
32-
docker push ${DOCKER_IMAGE} &&
33-
docker logout
46+
brew install hadolint
47+
hadolint ./Dockerfile

.hadolint.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ignored:
2+
- DL3008

Dockerfile

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
FROM ubuntu:18.04
22

3-
LABEL "com.github.actions.name"="Deploy to GitHub Pages for Static Site Generator"
4-
LABEL "com.github.actions.description"="A GitHub Action to deploy your static site to GitHub Pages with Static Site Generator"
5-
LABEL "com.github.actions.icon"="upload-cloud"
6-
LABEL "com.github.actions.color"="blue"
7-
8-
LABEL "repository"="https://github.com/peaceiris/actions-gh-pages"
9-
LABEL "homepage"="https://github.com/peaceiris/actions-gh-pages"
10-
LABEL "maintainer"="peaceiris"
11-
123
RUN apt-get update && apt-get install -y --no-install-recommends \
134
git \
145
openssh-client \

README.md

Lines changed: 87 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,25 @@ A GitHub Action to deploy your static site to GitHub Pages with [Static Site Gen
1818

1919
## Getting started
2020

21-
### Create `.github/workflows/gh-pages.yml`
21+
### (1) Add ssh deploy key
2222

23-
An example with Hugo action.
23+
Generate your deploy key with the following command.
24+
25+
```sh
26+
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f gh-pages -N ""
27+
# You will get 2 files:
28+
# gh-pages.pub (public key)
29+
# gh-pages (private key)
30+
```
31+
32+
Next, Go to **Repository Settings**
33+
34+
- Go to **Deploy Keys** and add your public key with the **Allow write access**
35+
- Go to **Secrets** and add your private key as `ACTIONS_DEPLOY_KEY`
36+
37+
### (2) Create `.github/workflows/gh-pages.yml`
38+
39+
An example yaml file with Hugo action.
2440

2541
- [peaceiris/actions-hugo: GitHub Actions for Hugo extended](https://github.com/peaceiris/actions-hugo)
2642

@@ -40,63 +56,92 @@ jobs:
4056
runs-on: ubuntu-18.04
4157
steps:
4258
- uses: actions/checkout@master
59+
4360
- name: build
44-
uses: peaceiris/[email protected]
45-
if: github.event.deleted == false
61+
uses: peaceiris/[email protected]
4662
with:
4763
args: --gc --minify --cleanDestinationDir
64+
4865
- name: deploy
49-
uses: peaceiris/[email protected]
50-
if: success()
66+
uses: peaceiris/[email protected]
5167
env:
52-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
5369
PUBLISH_BRANCH: gh-pages
5470
PUBLISH_DIR: ./public
5571
```
5672
73+
### Options
74+
75+
#### Pull action image from Docker Hub
76+
77+
You can pull a public docker image from Docker Hub.
78+
By pulling docker images, you can reduce the overall execution time of your workflow. In addition, `latest` tag is provided.
79+
80+
```diff
81+
- uses: peaceiris/[email protected]
82+
+ uses: docker://peaceiris/gh-pages:v2.0.0
83+
```
84+
85+
- [peaceiris/gh-pages - Docker Hub](https://hub.docker.com/r/peaceiris/gh-pages)
86+
87+
```diff
88+
- uses: peaceiris/[email protected]
89+
+ uses: docker://peaceiris/gha-hugo:v0.58.0
90+
```
91+
92+
- [peaceiris/gha-hugo - Docker Hub](https://hub.docker.com/r/peaceiris/gha-hugo)
93+
94+
### `GITHUB_TOKEN`
95+
96+
> **NOTES**: This action supports `GITHUB_TOKEN` but it has some problems to deploy to GitHub Pages. See #9
97+
98+
```diff
99+
- ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
100+
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
```
102+
57103

58104

59105
## Examples
60106

61107
### MkDocs
62108

63-
- [peaceiris/actions-pipenv: GitHub Actions for pipenv](https://github.com/peaceiris/actions-pipenv)
64-
- [main.workflow - peaceiris/mkdocs-material-boilerplate](https://github.com/peaceiris/mkdocs-material-boilerplate/blob/master/.github/main.workflow)
65-
66109
![peaceiris/actions-gh-pages latest version](https://img.shields.io/github/release/peaceiris/actions-gh-pages.svg?label=peaceiris%2Factions-gh-pages)
67110

68-
```hcl
69-
workflow "MkDocs workflow" {
70-
on = "push"
71-
resolves = ["deploy"]
72-
}
73-
74-
action "branch-filter" {
75-
uses = "actions/bin/filter@master"
76-
args = "branch master"
77-
}
78-
79-
action "pipenv-sync" {
80-
needs = ["branch-filter"]
81-
uses = "peaceiris/[email protected]"
82-
args = "sync"
83-
}
84-
85-
action "mkdocs-build" {
86-
needs = ["pipenv-sync"]
87-
uses = "peaceiris/[email protected]"
88-
args = ["run", "mkdocs", "build", "--config-file", "./mkdocs-sample.yml"]
89-
}
90-
91-
action "deploy" {
92-
needs = ["mkdocs-build"]
93-
uses = "peaceiris/[email protected]"
94-
env = {
95-
PUBLISH_DIR = "./site"
96-
PUBLISH_BRANCH = "gh-pages"
97-
}
98-
secrets = ["GITHUB_TOKEN"]
99-
}
111+
```yaml
112+
name: github pages
113+
114+
on:
115+
push:
116+
branches:
117+
- master
118+
119+
jobs:
120+
build-deploy:
121+
runs-on: ubuntu-18.04
122+
steps:
123+
- uses: actions/checkout@v1
124+
125+
- name: Set up Python
126+
uses: actions/setup-python@v1
127+
with:
128+
python-version: '3.6'
129+
architecture: 'x64'
130+
131+
- name: Install dependencies
132+
run: |
133+
pip install --upgrade pip
134+
pip install -r ./requirements.txt
135+
136+
- name: Build with MkDocs
137+
run: mkdocs build
138+
139+
- name: Deploy to GitHub Pages
140+
uses: peaceiris/[email protected]
141+
env:
142+
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
143+
PUBLISH_BRANCH: gh-pages
144+
PUBLISH_DIR: ./site
100145
```
101146

102147

action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: 'Deploy to GitHub Pages for Static Site Generator'
2+
description: 'A GitHub Action to deploy your static site to GitHub Pages with Static Site Generator'
3+
author: 'peaceiris'
4+
runs:
5+
using: 'docker'
6+
image: 'Dockerfile'
7+
branding:
8+
icon: 'upload-cloud'
9+
color: 'blue'

entrypoint.sh

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,25 @@ function print_info() {
1212
}
1313

1414
# check values
15-
if [ -z "${GITHUB_TOKEN}" ]; then
16-
print_error "not found GITHUB_TOKEN"
15+
if [ -n "${ACTIONS_DEPLOY_KEY}" ]; then
16+
17+
print_info "setup with ACTIONS_DEPLOY_KEY"
18+
19+
mkdir /root/.ssh
20+
ssh-keyscan -t rsa github.com > /root/.ssh/known_hosts
21+
echo "${ACTIONS_DEPLOY_KEY}" > /root/.ssh/id_rsa
22+
chmod 400 /root/.ssh/id_rsa
23+
24+
remote_repo="[email protected]:${GITHUB_REPOSITORY}.git"
25+
26+
elif [ -n "${GITHUB_TOKEN}" ]; then
27+
28+
print_info "setup with GITHUB_TOKEN"
29+
30+
remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
31+
32+
else
33+
print_error "not found ACTIONS_DEPLOY_KEY or GITHUB_TOKEN"
1734
exit 1
1835
fi
1936

@@ -27,7 +44,6 @@ if [ -z "${PUBLISH_DIR}" ]; then
2744
exit 1
2845
fi
2946

30-
remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
3147
remote_branch="${PUBLISH_BRANCH}"
3248

3349
local_dir="${HOME}/$(tr -cd 'a-f0-9' < /dev/urandom | head -c 32)"

0 commit comments

Comments
 (0)