cedrickring / golang-action

A GitHub Action to run Go commands
Apache License 2.0
134 stars 33 forks source link

Add build/test/publish actions for golang-action #3

Closed dougnukem closed 5 years ago

dougnukem commented 5 years ago

Adds in a Github actions workflow to:

I was able to test and run it locally using:


Running locally it runs all the steps and stops at Publish (because its not running from `@master`

$ act [Test] git clone 'https://github.com/actions/action-builder' # ref=master [Lint] git clone 'https://github.com/actions/action-builder' # ref=master [Test] docker build -t action-builder:master /var/folders/tv/d5hn3rbs2p776ybs3g92_00w0000gr/T/act/actions/action-builder/shell@master/shell [Test] docker run image=action-builder:master entrypoint=["make"] cmd=["test"] [Lint] docker build -t action-builder:master /var/folders/tv/d5hn3rbs2p776ybs3g92_00w0000gr/T/act/actions/action-builder/shell@master/shell [Lint] docker run image=action-builder:master entrypoint=["make"] cmd=["lint"] test && bats || exit 0 shellcheck entrypoint.sh dockerfile_lint -r /github/workspace/.dockerfile_lint/github_actions.yaml Dockerfile

Analyzing Dockerfile

--------INFO---------

INFO: There is no 'CMD' instruction. In most cases it is helpful to include reasonable defaults for CMD. Reference -> https://docs.docker.com/engine/reference/builder/#cmd

[Build] git clone 'https://github.com/actions/docker' # ref=master [Build] docker build -t docker:master /var/folders/tv/d5hn3rbs2p776ybs3g92_00w0000gr/T/act/actions/docker/cli@master/cli [Build] docker run image=docker:master entrypoint=[] cmd=["build" "-t" "golang-action" "."] Sending build context to Docker daemon 234.5kB Step 1/11 : FROM golang:1.11 ---> 901414995ecd Step 2/11 : LABEL name="Golang Action" ---> Using cache ---> 2f9e261416ee Step 3/11 : LABEL maintainer="Cedric Kring" ---> Using cache ---> c9db4f214467 Step 4/11 : LABEL version="1.1.0" ---> Using cache ---> 7aad81ee87c5 Step 5/11 : LABEL repository="https://github.com/cedrickring/golang-action" ---> Using cache ---> 32b835786c11 Step 6/11 : LABEL com.github.actions.name="Golang Action" ---> Using cache ---> 5dd6d449b474 Step 7/11 : LABEL com.github.actions.description="Run Golang commands" ---> Using cache ---> 5aafadd36c66 Step 8/11 : LABEL com.github.actions.icon="box" ---> Using cache ---> 482e77276a8f Step 9/11 : LABEL com.github.actions.color="blue" ---> Using cache ---> 60c1df74031d Step 10/11 : COPY entrypoint.sh /entrypoint.sh ---> Using cache ---> c666dae6f42c Step 11/11 : ENTRYPOINT ["/entrypoint.sh"] ---> Using cache ---> de4a9694e3c7 Successfully built de4a9694e3c7 Successfully tagged golang-action:latest [Publish Filter] git clone 'https://github.com/actions/bin' # ref=master [Publish Filter] docker build -t bin:master /var/folders/tv/d5hn3rbs2p776ybs3g92_00w0000gr/T/act/actions/bin/filter@master/filter [Publish Filter] docker run image=bin:master entrypoint=[] cmd=["branch" "master"] refs/heads/action-lint does not match refs/heads/master Error: exit with NEUTRAL: 78


I also added a Publishing flow that will tag and publish the golang-action to Docker hub when commits are pushed to `@master`.

It will tag using the version in the actions `Dockerfile`:
For example:
- https://hub.docker.com/r/dougnukem/golang-action/tags

Dockerfile Github Action Version: 1.1.0

golang-action:1.1.0

Major version

golang-action:1

Commit hash

golang-action:a467e57

Branch ref

golang-action:action-lint



**NOTE**
- This requires configuring Github action env variable secrets to login to https://hub.docker.com/r/cedrickring/ docker hub repo 
   - `DOCKER_USERNAME`, `DOCKER_PASSWORD`
cedrickring commented 5 years ago

First of all, thanks for adding dockerlint and adding a gh-actions workflow. I just got two small questions;

Otherwise LGTM 💯

dougnukem commented 5 years ago

Instead of filtering for the master branch in main.workflow, why don't we add a second workflow that triggers on a release?

  • That makes sense I'll look into changing that filter

Is it really nessecary to build the image? I thought gh-actions is designed to build the required action when its used... Mainly the build step is to ensure that the Dockerfile is valid and builds successfully, so that any errors would hopefully be caught by that build status before that breaking change gets in (e.g. commit status will be failed in the pull-request)

dougnukem commented 5 years ago

@cedrickring I changed the workflow to only run the Docker publish stuff on release event:

workflow "Build and Publish" {
  on = "release"
  resolves = "Docker Publish"
}
         ╔════════════════╗
         ║ EVENT: release ║
         ╚════════════════╝
                 ⬇
 ╭──────╮ ╭──────╮ ╭──────────────╮
 │ Lint │ │ Test │ │ Docker Login │
 ╰──────╯ ╰──────╯ ╰──────────────╯
                 ⬇
             ╭───────╮
             │ Build │
             ╰───────╯
                 ⬇
           ╭────────────╮
           │ Docker Tag │
           ╰────────────╯
                 ⬇
         ╭────────────────╮
         │ Docker Publish │
         ╰────────────────╯

  ╔═════════════╗
  ║ EVENT: push ║
  ╚═════════════╝
        ⬇
 ╭──────╮ ╭──────╮
 │ Lint │ │ Test │
 ╰──────╯ ╰──────╯
        ⬇
     ╭───────╮
     │ Build │
     ╰───────╯