Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

v2.0.0 #33

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
on: pull_request
name: Run checks
jobs:
go-checks:
name: Run go checks
go-test:
name: Test go configurations
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Test Go Modules Vendor
uses: ./
env:
IMPORT: cedrickring/golang-action
PROJECT_PATH: ./tests/projects/go_modules_vendored
- name: Test Go Modules
uses: ./
env:
IMPORT: cedrickring/golang-action
PROJECT_PATH: ./tests/projects/go_modules
- name: Test Go Standard
uses: ./
env:
IMPORT: cedrickring/golang-action
PROJECT_PATH: ./tests/projects/go_standard
- uses: actions/checkout@master
- name: Test Go Modules Vendor
uses: ./
with:
projectPath: tests/projects/go_modules_vendored
- name: Test Go Modules
uses: ./
with:
projectPath: tests/projects/go_modules
- name: Test Go Standard
uses: ./
with:
projectPath: tests/projects/go_standard
action-checks:
name: Run action checks
runs-on: ubuntu-latest
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ jobs:
- uses: actions/checkout@master
- name: Test Go Modules Vendor
uses: ./
env:
IMPORT: cedrickring/golang-action
PROJECT_PATH: ./tests/projects/go_modules_vendored
with:
projectPath: tests/projects/go_modules_vendored
- name: Test Go Modules
uses: ./
env:
IMPORT: cedrickring/golang-action
PROJECT_PATH: ./tests/projects/go_modules
with:
projectPath: tests/projects/go_modules
- name: Test Go Standard
uses: ./
env:
IMPORT: cedrickring/golang-action
PROJECT_PATH: ./tests/projects/go_standard
with:
projectPath: tests/projects/go_standard
test:
name: Run tests and build
runs-on: ubuntu-latest
Expand Down
8 changes: 1 addition & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@ FROM golang:1.15

LABEL name="Golang Action"
LABEL maintainer="Cedric Kring"
LABEL version="1.6.0"
LABEL version="v2.0.0"
LABEL repository="https://github.com/cedrickring/golang-action"

LABEL com.github.actions.name="Golang Action"
LABEL com.github.actions.description="Run Golang commands"
LABEL com.github.actions.icon="box"
LABEL com.github.actions.color="blue"

# Install dep and check sha256 checksum matches for version 0.5.4 https://github.com/golang/dep/releases/tag/v0.5.4
RUN set -eux; \
curl -L -s https://github.com/golang/dep/releases/download/v0.5.4/dep-linux-amd64 -o "$GOPATH/bin/dep"; \
echo "40a78c13753f482208d3f4bea51244ca60a914341050c588dad1f00b1acc116c $GOPATH/bin/dep" | sha256sum -c -; \
chmod +x "${GOPATH}/bin/dep";

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
Expand Down
45 changes: 12 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

This Action allows you to run Go commands with your code. It will automatically setup your workspace (`~/go/src/github.com/<your-name>/<repo>`) before the command is run.

**NOTE**: As of `v2.0.0` the `dep` support will be dropped for go versions greater than `1.14.x`.

## How to use

Create a `workflow.yaml` file in `.github/workflows` with the following contents:
Expand All @@ -18,55 +20,32 @@ jobs:
- uses: actions/checkout@master

- name: run
uses: cedrickring/golang-action@1.6.0
uses: cedrickring/golang-action@v2.0.0
```


If no args are specified and a `Makefile` is detected, this action will run `make`. Otherwise `go test` and `go build` will be run.
To run a custom command, just use:
To run a custom command, use:
```yaml
steps:
- name: Run custom command
uses: cedrickring/golang-action@1.6.0
uses: cedrickring/golang-action@v2.0.0
with:
args: make my-target
```

If your repository's `import` name is different from the path on GitHub,
provide the `import` name by adding an environment variable
`IMPORT=import/name`. This may be useful if you have forked an open
source Go project:
```yaml
steps:
- name: Run with custom import path
uses: cedrickring/[email protected]
env:
IMPORT: "root/repo"
```


To use Go Modules add `GO111MODULE=on` to the step:
```yaml
steps:
- name: Go Modules
uses: cedrickring/[email protected]
env:
GO111MODULE: "on"
customCommand: make my-target
```


If your go project is not located at the root of the repo you can also specify environment variable `PROJECT_PATH`:
```yaml
steps:
- name: Custom project path
uses: cedrickring/golang-action@1.6.0
env:
PROJECT_PATH: "./path/in/my/project"
uses: cedrickring/golang-action@v2.0.0
with:
projectPath: "path/in/my/project"
```

To use a specific golang version (1.10, 1.11, 1.12, 1.13, 1.14, 1.15), defaults to the latest version:
To use a specific golang version (1.14, 1.15), defaults to the latest version:
```yaml
steps:
- name: Use Go 1.11
uses: cedrickring/golang-action/go1.[email protected].0
- name: Use Go 1.14
uses: cedrickring/golang-action/go1.[email protected].0
```
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
name: 'Golang Action'
description: 'Run Golang commands'
author: '@cedrickring'
inputs:
projectPath:
description: 'Path to the go project inside the repository structure'
required: false
default: '.'
customCommand:
description: 'Command to run'
required: false
default: ''
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.customCommand }}
branding:
icon: 'box'
color: 'blue'
4 changes: 2 additions & 2 deletions build/semver
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -o errexit -o nounset -o pipefail

SEMVER_REGEX="^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"
SEMVER_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"

PROG=semver
PROG_VERSION=2.1.0
Expand Down Expand Up @@ -76,7 +76,7 @@ function validate-version {
echo "$version"
fi
else
error "version $version does not match the semver scheme 'X.Y.Z(-PRERELEASE)(+BUILD)'. See help for more information."
error "version $version does not match the semver scheme 'vX.Y.Z(-PRERELEASE)(+BUILD)'. See help for more information."
fi
}

Expand Down
35 changes: 4 additions & 31 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@

set -e

if [ -z "${IMPORT}" ]; then
IMPORT="${GITHUB_REPOSITORY}"
fi
WORKDIR="${GOPATH}/src/github.com/${IMPORT}"

# PROJECT_PATH specifies the subdirectory in the working directory that the Go project is
if [ -z "${PROJECT_PATH}" ]; then
PROJECT_PATH="."
if [ -z "${INPUT_PROJECTPATH}" ]; then
INPUT_PROJECTPATH="."
fi

# Go can only find dependencies if they're under $GOPATH/src.
# GitHub Actions mounts your repository outside of $GOPATH.
# So symlink the repository into $GOPATH, and then cd to it.
mkdir -p "$(dirname "${WORKDIR}")"
ln -s "${PWD}" "${WORKDIR}"
cd "${WORKDIR}/${PROJECT_PATH}"
cd "${GITHUB_WORKSPACE}/${INPUT_PROJECTPATH}"

# If a command was specified with `args="..."`, then run it. Otherwise,
# If a command was specified with `args: "..."`, then run it. Otherwise,
# look for something useful to run.
if [ $# -eq 0 ] || [ "$*" = "" ]; then
if [ -r Makefile ]; then
Expand All @@ -34,23 +24,6 @@ if [ $# -eq 0 ] || [ "$*" = "" ]; then
# Ensure no go.mod changes are made that weren't committed
export GOFLAGS="-mod=readonly"
fi
else
if [ -r Gopkg.toml ]; then
# Check if using vendored dependencies
if [ -d "vendor" ]; then
# Check that dep is in sync with /vendor dependencies and that running dep ensure doesn't result in modifications to Gopkg.lock/Gopkg.toml
"$GOPATH/bin/dep" ensure && "$GOPATH/bin/dep" check
git_workspace_status="$(git status --porcelain)"
if [ -n "${git_workspace_status}" ]; then
echo "Unexpected changes were found in dep /vendored. Please run $(dep ensure) and commit changes:";
echo "${git_workspace_status}";
exit 1;
fi
else
# Run dep ensure to download and sync dependencies
"$GOPATH/bin/dep" ensure
fi
fi
fi
go build ./...
go test ./...
Expand Down
22 changes: 0 additions & 22 deletions go1.10/Dockerfile

This file was deleted.

9 changes: 0 additions & 9 deletions go1.10/action.yml

This file was deleted.

60 changes: 0 additions & 60 deletions go1.10/entrypoint.sh

This file was deleted.

22 changes: 0 additions & 22 deletions go1.11/Dockerfile

This file was deleted.

9 changes: 0 additions & 9 deletions go1.11/action.yml

This file was deleted.

Loading