Skip to content

Commit c9d9bca

Browse files
authored
Merge pull request #3 from enriikke/migrate-to-new-syntax
Migrate to JavaScript action
2 parents 6f11d33 + 0a1e833 commit c9d9bca

File tree

395 files changed

+78727
-155
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

395 files changed

+78727
-155
lines changed

Diff for: Dockerfile

-18
This file was deleted.

Diff for: README.md

+57-71
Original file line numberDiff line numberDiff line change
@@ -7,66 +7,58 @@ GitHub Action to build and deploy your Gatsby site to GitHub Pages ❤️🎩
77
This GitHub Action will run `gatsby build` at the root of your repository and
88
deploy it to GitHub Pages for you! Here's a basic workflow example:
99

10-
```workflow
11-
workflow "Gatsby to GitHub Pages" {
12-
on = "push"
13-
resolves = ["Publish"]
14-
}
15-
16-
action "Publish" {
17-
uses = "enriikke/gatsby-gh-pages-action@master"
18-
secrets = ["ACCESS_TOKEN"]
19-
}
20-
```
21-
22-
It's recommended to use this Action combined with the [Filters Action](https://github.com/actions/bin/tree/c6471707d308175c57dfe91963406ef205837dbd/filter)
23-
to specify only the branch(es) you want to trigger a build.
24-
25-
```workflow
26-
workflow "Gatsby to GitHub Pages" {
27-
on = "push"
28-
resolves = ["Publish"]
29-
}
30-
31-
action "On Dev" {
32-
uses = "actions/bin/filter@master"
33-
args = "branch dev"
34-
}
35-
36-
action "Publish" {
37-
uses = "enriikke/gatsby-gh-pages-action@@1.0.1"
38-
needs = ["On Dev"]
39-
secrets = ["ACCESS_TOKEN"]
40-
}
10+
```yml
11+
name: Gatsby Publish
12+
13+
on:
14+
push:
15+
branches:
16+
- dev
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v1
23+
- uses: enriikke/gatsby-gh-pages-action@v2
24+
with:
25+
access-token: ${{ secrets.ACCESS_TOKEN }}
4126
```
4227
4328
### Knobs & Handles
4429
4530
This Action is fairly simple but it does provide you with a couple of
4631
configuration options:
4732
48-
- **DEPLOY_BRANCH**: The branch expected by GitHub to have the static files
33+
- **access-token**: A [GitHub Personal Access Token][github-access-token] with
34+
the `repo` scope. This is **required** to push the site to your repo after
35+
Gatsby finish building it. You should store this as a [secret][github-repo-secret]
36+
in your repository. Provided as an [input][github-action-input].
37+
38+
- **deploy-branch**: The branch expected by GitHub to have the static files
4939
needed for your site. For org and user pages it should always be `master`.
50-
This is where the output of `gatsby build` will be pushed to. Defined as an
51-
[environment variable](https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#environment-variables).
40+
This is where the output of `gatsby build` will be pushed to. Provided as an
41+
[input][github-action-input].
5242
Defaults to `master`.
5343

54-
- **ARGS**: Additional arguments that get passed to `gatsby build`. See the
55-
[Gatsby documentation](https://www.gatsbyjs.org/docs/gatsby-cli/#build) for a
56-
list of allowed options. Given as [workflow args](https://developer.github.com/actions/creating-github-actions/creating-a-docker-container/#cmd).
44+
- **gatsby-args**: Additional arguments that get passed to `gatsby build`. See the
45+
[Gatsby documentation][gatsby-build-docs] for a list of allowed options.
46+
Provided as an [input][github-action-input].
5747
Defaults to nothing.
5848

5949
### Org or User Pages
6050

6151
Create a repository with the format `<YOUR/ORG USERNAME>.github.io`, push your
62-
Gatsby source code to a branch different than your `DEPLOY_BRANCH` and add this
63-
GitHub Action to your workflow! 🚀😃
52+
Gatsby source code to a branch other than `master` and add this GitHub Action to
53+
your workflow! 🚀😃
6454

6555
### Repository Pages
6656

67-
Repo pages work a little different because the URL includes a trailing path with
68-
the repository name, like `https://username.github.io/reponame/`. You need to
69-
tell Gatsby what the path prefix is via `gatsby-config.js`:
57+
Repo pages give you the option to push your static site to either `master` or
58+
`gh-pages` branches. They also work a little different because the URL includes
59+
a trailing path with the repository name, like
60+
`https://username.github.io/reponame/`. You need to tell Gatsby what the path
61+
prefix is via `gatsby-config.js`:
7062

7163
```js
7264
module.exports = {
@@ -77,44 +69,38 @@ module.exports = {
7769
Additionally, you need to tell the `gatsby build` command to use it by passing
7870
the `--prefix-paths` as an argument. Here's an example workflow for that:
7971

80-
```workflow
81-
workflow "Gatsby to GitHub Pages" {
82-
on = "push"
83-
resolves = ["Publish"]
84-
}
85-
86-
action "Publish" {
87-
uses = "enriikke/gatsby-gh-pages-action@master"
88-
args = "--prefix-paths"
89-
secrets = ["ACCESS_TOKEN"]
90-
}
72+
```yml
73+
name: Gatsby Publish
74+
75+
on:
76+
push:
77+
branches:
78+
- dev
79+
80+
jobs:
81+
build:
82+
runs-on: ubuntu-latest
83+
steps:
84+
- uses: actions/checkout@v1
85+
- uses: enriikke/gatsby-gh-pages-action@v2
86+
with:
87+
access-token: ${{ secrets.ACCESS_TOKEN }}
88+
deploy-branch: gh-pages
89+
gatsby-args: --prefix-paths
9190
```
9291

93-
🤩 Note that **NON** of this is necessary if you are using custom domains.🤩
94-
95-
## Requirements
96-
97-
A [GitHub Personal Access Token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/)
98-
with the `repo` scope is needed to run this Action. This is important! This is
99-
**NOT** the same as the `GITHUB_TOKEN` that can be included as part of an Action.
100-
101-
Just as important is that this personal access token needs to be provided as a
102-
[secret](https://developer.github.com/actions/creating-workflows/storing-secrets/)
103-
with the name `ACCESS_TOKEN`, **NOT** as an environment variable. The reason
104-
being that secrets get encrypted while environment variables do **NOT**.
105-
106-
Sorry for being so _negative_ just now ☝️. I just want to make sure nobody
107-
accidentally exposes any sensitive information. Let's keep access tokens safe! 😉😇
108-
10992
### Assumptions
11093

11194
This Action assumes that your Gatsby code sits at the root of your repository
11295
and `gatsby build` outputs to the `public` directory. As of this writing, Gatsby
11396
doesn't provide a way to customize the build directory so this should be a safe
11497
assumption.
11598

116-
11799
## That's It
118100

119-
Have fun building!
101+
Have fun building!
120102

103+
[gatsby-build-docs]: https://www.gatsbyjs.org/docs/gatsby-cli/#build
104+
[github-access-token]: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line
105+
[github-action-input]: https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepswith
106+
[github-repo-secret]: https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables

Diff for: action.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: "Gatsby Publish"
2+
description: "Build and deploy your Gatsby site to GitHub Pages."
3+
branding:
4+
icon: "book-open"
5+
color: "purple"
6+
inputs:
7+
access-token:
8+
description: "A personal access token needed to push your site after it has been built."
9+
required: true
10+
deploy-branch:
11+
description: "The branch expected by GitHub to have the static files needed for your site."
12+
required: false
13+
default: "master"
14+
gatsby-args:
15+
description: "Additional arguments that get passed to `gatsby build`."
16+
required: false
17+
default: ""
18+
runs:
19+
using: "node12"
20+
main: "index.js"

Diff for: entrypoint

-66
This file was deleted.

Diff for: index.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const core = require("@actions/core")
2+
const github = require("@actions/github")
3+
const ioUtil = require("@actions/io/lib/io-util")
4+
const exec = require("@actions/exec")
5+
6+
async function run() {
7+
try {
8+
const accessToken = core.getInput("access-token")
9+
if (!accessToken) {
10+
core.setFailed(
11+
"No personal access token found. Please provide one by setting the `access-token` input for this action."
12+
)
13+
return
14+
}
15+
16+
const deployBranch = core.getInput("deploy-branch")
17+
if (!deployBranch) deployBranch = "master"
18+
19+
if (github.context.ref === `refs/heads/${deployBranch}`) {
20+
console.log(`Triggered by branch used to deploy: ${github.context.ref}.`)
21+
console.log("Nothing to deploy.")
22+
return
23+
}
24+
25+
const pkgManager = (await ioUtil.exists("./yarn.lock")) ? "yarn" : "npm"
26+
console.log(`Installing your site's dependencies using ${pkgManager}.`)
27+
await exec.exec(`${pkgManager} install`)
28+
console.log("Finished installing dependencies.")
29+
30+
const gatsbyArgs = core.getInput("gatsby-args")
31+
console.log("Ready to build your Gatsby site!")
32+
console.log(`Building with: ${pkgManager} run gatsby build ${gatsbyArgs}`)
33+
await exec.exec(`${pkgManager} run gatsby build`, [gatsbyArgs])
34+
console.log("Finished buidling your site.")
35+
36+
// TODO: copy CNAME to ./public
37+
38+
const repo = `${github.context.repo.owner}/${github.context.repo.repo}`
39+
const repoURL = `https://${accessToken}@github.com/${repo}.git`
40+
console.log("Ready to deploy your new shiny site!")
41+
console.log(`Deploying to repo: ${repo} and branch: ${deployBranch}`)
42+
console.log(
43+
"You can configure the deploy branch by setting the `deploy-branch` input for this action."
44+
)
45+
await exec.exec(`git init`, [], { cwd: "./public" })
46+
await exec.exec(`git config user.name`, [github.context.actor], {
47+
cwd: "./public",
48+
})
49+
await exec.exec(
50+
`git config user.email`,
51+
[`${github.context.actor}@users.noreply.github.com`],
52+
{ cwd: "./public" }
53+
)
54+
await exec.exec(`git add`, ["."], { cwd: "./public" })
55+
await exec.exec(
56+
`git commit`,
57+
["-m", `deployed via Gatsby Publish Action 🎩 for ${github.context.sha}`],
58+
{ cwd: "./public" }
59+
)
60+
await exec.exec(`git push`, ["-f", repoURL, `master:${deployBranch}`], {
61+
cwd: "./public",
62+
})
63+
console.log("Finished deploying your site.")
64+
65+
console.log("Enjoy! ✨")
66+
} catch (error) {
67+
core.setFailed(error.message)
68+
}
69+
}
70+
71+
run()

Diff for: node_modules/.bin/semver

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/.bin/which

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: node_modules/@actions/core/LICENSE.md

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)