Skip to content

Commit

Permalink
All users to install Go into the action container.
Browse files Browse the repository at this point in the history
Resolves #41
Resolves #38
  • Loading branch information
benmatselby committed Feb 3, 2022
1 parent 891f91f commit cba355d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 1.13.0

- All users to optionally install Go within the action environment. This is not required to deploy the Hugo site.

## 1.12.0

- Always pull the latest Hugo release, if there is not one set.
Expand Down
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
FROM debian:buster-slim
LABEL maintainer="Ben Selby <[email protected]>"

##
# Define the location of Go.
# We may not always install it, but if we do, it's here.
##
ENV GOPATH /go
ENV PATH /go/bin:/usr/local/go/bin:$PATH

##
# Installation of all the tooling we need.
##
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
Expand All @@ -9,6 +19,12 @@ RUN apt-get update && \
git && \
rm -rf /var/lib/apt/lists/*

##
# Copy over the action script.
##
COPY action.sh /usr/bin/action.sh

##
# Run the action.
##
ENTRYPOINT ["action.sh"]
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ This GitHub action will build your [Hugo site](https://gohugo.io/), and then pub

## Environment Variables

- `CNAME`: Contents of a `CNAME` file.
- `GITHUB_ACTOR`: The name of the person or app that initiated the workflow. For example, octocat. [See here](https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#environment-variables).
- `TARGET_REPO`: This is the repo slug for the GitHub pages site. e.g. `benmatselby/benmatselby.github.io`.
- `TARGET_BRANCH`: This is the branch to push the public files e.g. `docs`. Default is `master` branch.
- `HUGO_VERSION`: This allows you to control which version of Hugo you want to use. The default is to pull the latest version.
- `HUGO_EXTENDED`: If set to `true`, the _extended_ version of Hugo will be used. Default is `false`.
- `GO_VERSION`: The version of Go you may want to install. This is not required for basic operation. Values should be in the format of `1.17`.
- `HUGO_ARGS`: Arguments passed to `hugo`.
- `CNAME`: Contents of a `CNAME` file.
- `HUGO_EXTENDED`: If set to `true`, the _extended_ version of Hugo will be used. Default is `false`.
- `HUGO_VERSION`: This allows you to control which version of Hugo you want to use. The default is to pull the latest version.
- `TARGET_BRANCH`: This is the branch to push the public files e.g. `docs`. Default is `master` branch.
- `TARGET_REPO`: This is the repo slug for the GitHub pages site. e.g. `benmatselby/benmatselby.github.io`.

## Example

Expand Down
36 changes: 36 additions & 0 deletions action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
set -e
set -o pipefail

###
# Environment variable definitions.
##
if [[ -n "${TOKEN}" ]]; then
GITHUB_TOKEN=${TOKEN}
fi
Expand Down Expand Up @@ -35,11 +38,42 @@ else
EXTENDED_URL=""
fi

###
# Downloading of Hugo.
###
echo "Downloading Hugo: ${HUGO_VERSION}${EXTENDED_INFO}"
URL=https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${EXTENDED_URL}${HUGO_VERSION}_Linux-64bit.deb
echo "Using '${URL}' to download Hugo"
curl -sSL "${URL}" > /tmp/hugo.deb && dpkg --force architecture -i /tmp/hugo.deb


###
# Optionally install Go.
###
# shellcheck disable=SC2153
if [[ -n "${GO_VERSION}" ]]; then
echo "Installing Go: ${GO_VERSION}"

curl -sL "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" > /tmp/go.tar.gz
tar -C /tmp -xf /tmp/go.tar.gz
mv /tmp/go /go
rm -rf \
/usr/local/go/pkg/*/cmd \
/usr/local/go/pkg/bootstrap \
/usr/local/go/pkg/obj \
/usr/local/go/pkg/tool/*/api \
/usr/local/go/pkg/tool/*/go_bootstrap \
/usr/local/go/src/cmd/dist/dist \
/tmp/go.tag.gz

This comment has been minimized.

Copy link
@muratcanakcay

muratcanakcay Jul 14, 2022

I guess there's a typo here. Shouldn't it be /tmp/go.tar.gz instead of /tmp/go.tag.gz ?

This comment has been minimized.

Copy link
@benmatselby

benmatselby Jul 14, 2022

Author Owner

You're absolutely right.

This comment has been minimized.

Copy link
@benmatselby

benmatselby Jul 14, 2022

Author Owner

You're absolutely right.

This comment has been minimized.

Copy link
@benmatselby

benmatselby Jul 15, 2022

Author Owner

Thanks for flagging this @muratcanakcay

PR now merged

This comment has been minimized.

Copy link
@muratcanakcay

muratcanakcay Jul 15, 2022

Thanks to you for the github action @benmatselby. It's made my hugo deploy so easy. Cheers!


# Provide version details and sanity check installation
echo "Installed Go: ${GO_VERSION}"
go version
fi

###
# Build the site.
###
echo "Building the Hugo site with: 'hugo ${HUGO_ARGS}'"
hugo "${HUGO_ARGS}"

Expand Down Expand Up @@ -68,7 +102,9 @@ fi
echo "Getting hash for base repository commit"
HASH=$(echo "${GITHUB_SHA}" | cut -c1-7)

###
# Now add all the changes and commit and push
###
if [[ "${TARGET_BRANCH}" != "master" ]]; then
git checkout -b ${TARGET_BRANCH}
fi
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ inputs:
github_token:
description: "Your PAT to authorise the action to do things."
required: true
go_version:
description: "The version of Go to install. Go won't be installed if this isn't set."
required: false
hugo_args:
description: "Any extra arguments to pass to Hugo."
required: false
Expand Down

0 comments on commit cba355d

Please sign in to comment.