Skip to content

Commit

Permalink
migrate: GitHub Actions v2 YAML workflow setting example with hugo
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris committed Aug 21, 2019
1 parent 5b4ace2 commit 6492b52
Showing 1 changed file with 26 additions and 32 deletions.
58 changes: 26 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A GitHub Action to deploy your static site to GitHub Pages with [Static Site Gen

## Getting started

### Create `.github/main.workflow`
### Create `.github/workflows/gh-pages.yml`

An example with Hugo action.

Expand All @@ -25,37 +25,31 @@ An example with Hugo action.
![peaceiris/actions-hugo latest version](https://img.shields.io/github/release/peaceiris/actions-hugo.svg?label=peaceiris%2Factions-hugo)
![peaceiris/actions-gh-pages latest version](https://img.shields.io/github/release/peaceiris/actions-gh-pages.svg?label=peaceiris%2Factions-gh-pages)

```hcl
workflow "GitHub Pages" {
on = "push"
resolves = ["deploy"]
}
action "is-branch-master" {
uses = "actions/bin/filter@master"
args = "branch master"
}
action "is-not-branch-deleted" {
uses = "actions/bin/filter@master"
args = "not deleted"
}
action "build" {
needs = ["is-branch-master", "is-not-branch-deleted"]
uses = "peaceiris/actions-hugo@v0.56.3"
args = ["--gc", "--minify", "--cleanDestinationDir"]
}
action "deploy" {
needs = "build"
uses = "peaceiris/actions-gh-pages@v1.1.0"
env = {
PUBLISH_DIR = "./public"
PUBLISH_BRANCH = "gh-pages"
}
secrets = ["GITHUB_TOKEN"]
}
```yaml
name: github-pages

on:
push:
branches:
- master

jobs:
build-deploy:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@master
- name: build
uses: peaceiris/actions-hugo@v0.57.2
if: github.event.deleted == false
with:
args: --gc --minify --cleanDestinationDir
- name: deploy
uses: peaceiris/actions-gh-pages@v1.1.0
if: success()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PUBLISH_BRANCH: gh-pages
PUBLISH_DIR: ./public
```

| Workflow overview | Actions log |
Expand Down

5 comments on commit 6492b52

@franzliedke
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why the if: success() is necessary?

@peaceiris
Copy link
Owner Author

@peaceiris peaceiris commented on 6492b52 Sep 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the build step finishes with neutral, the deploy step starts. To prevent it, we need if: success()

Screen Shot 2019-09-04 at 21 17 04

@peaceiris
Copy link
Owner Author

@peaceiris peaceiris commented on 6492b52 Sep 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These days, GitHub Actions v2 seems to ignore a delete event by default. Maybe, we no longer need those if statements (if: github.event.deleted == false and if: success()).

I created #12

@franzliedke
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peaceiris Thanks for the answer! When would the build step finish with neutral? When it doesn't execute because of its own if condition?

@peaceiris
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Steps will stop with neutral status when the if condition is false.
When we delete a branch or a tag, GitHub Actions detect a delete event. (github.event.deleted == true) Thus, we can set if: github.event.deleted == false to prevent from running a step.

Please sign in to comment.