├── .github └── workflows │ ├── go.yml │ └── integration.yml ├── Dockerfile ├── LICENSE ├── README.md ├── action.yml └── main.go /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: [push, pull_request] 3 | jobs: 4 | build: 5 | name: Build 6 | runs-on: ubuntu-latest 7 | steps: 8 | - name: Set up Go 1.13 9 | uses: actions/setup-go@v1 10 | with: 11 | go-version: 1.13 12 | id: go 13 | 14 | - uses: actions/checkout@v1 15 | 16 | - name: Build 17 | run: | 18 | go get -d -v 19 | go build -v . 20 | -------------------------------------------------------------------------------- /.github/workflows/integration.yml: -------------------------------------------------------------------------------- 1 | name: Integration Test 2 | on: [push] 3 | jobs: 4 | build: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@master 8 | - name: Self test 9 | id: selftest 10 | 11 | # Put your action repo here 12 | uses: jacobtomlinson/go-container-action@master 13 | 14 | - name: Check outputs 15 | run: | 16 | test "${{ steps.selftest.outputs.myOutput }}" == "Hello world" 17 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.13 as builder 2 | 3 | WORKDIR /app 4 | COPY . /app 5 | 6 | RUN go get -d -v 7 | 8 | # Statically compile our app for use in a distroless container 9 | RUN CGO_ENABLED=0 go build -ldflags="-w -s" -v -o app . 10 | 11 | # A distroless container image with some basics like SSL certificates 12 | # https://github.com/GoogleContainerTools/distroless 13 | FROM gcr.io/distroless/static 14 | 15 | COPY --from=builder /app/app /app 16 | 17 | ENTRYPOINT ["/app"] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2018 GitHub, Inc. and contributors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Go Container Action Template 2 | 3 | [![Action Template](https://img.shields.io/badge/Action%20Template-Go%20Container%20Action-blue.svg?colorA=24292e&colorB=0366d6&style=flat&longCache=true&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAM6wAADOsB5dZE0gAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAERSURBVCiRhZG/SsMxFEZPfsVJ61jbxaF0cRQRcRJ9hlYn30IHN/+9iquDCOIsblIrOjqKgy5aKoJQj4O3EEtbPwhJbr6Te28CmdSKeqzeqr0YbfVIrTBKakvtOl5dtTkK+v4HfA9PEyBFCY9AGVgCBLaBp1jPAyfAJ/AAdIEG0dNAiyP7+K1qIfMdonZic6+WJoBJvQlvuwDqcXadUuqPA1NKAlexbRTAIMvMOCjTbMwl1LtI/6KWJ5Q6rT6Ht1MA58AX8Apcqqt5r2qhrgAXQC3CZ6i1+KMd9TRu3MvA3aH/fFPnBodb6oe6HM8+lYHrGdRXW8M9bMZtPXUji69lmf5Cmamq7quNLFZXD9Rq7v0Bpc1o/tp0fisAAAAASUVORK5CYII=)](https://github.com/jacobtomlinson/go-container-action) 4 | [![Actions Status](https://github.com/jacobtomlinson/go-container-action/workflows/Build/badge.svg)](https://github.com/jacobtomlinson/go-container-action/actions) 5 | [![Actions Status](https://github.com/jacobtomlinson/go-container-action/workflows/Integration%20Test/badge.svg)](https://github.com/jacobtomlinson/go-container-action/actions) 6 | 7 | This is a template for creating GitHub actions and contains a small Go application which will be built into a minimal [Container Action](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-a-docker-container-action). Our final container from this template is ~3MB, yours may be a little bigger once you add some code, but it'll still be tiny! 8 | 9 | In `main.go` you will find a small example of accessing Action inputs and returning Action outputs. For more information on communicating with the workflow see the [development tools for GitHub Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/development-tools-for-github-actions). 10 | 11 | > 🏁 To get started, click the `Use this template` button on this repository [which will create a new repository based on this template](https://github.blog/2019-06-06-generate-new-repositories-with-repository-templates/). 12 | 13 | ## Usage 14 | 15 | Describe how to use your action here. 16 | 17 | ### Example workflow 18 | 19 | ```yaml 20 | name: My Workflow 21 | on: [push, pull_request] 22 | jobs: 23 | build: 24 | runs-on: ubuntu-latest 25 | steps: 26 | - uses: actions/checkout@master 27 | - name: Run action 28 | 29 | # Put your action repo here 30 | uses: me/myaction@master 31 | 32 | # Put an example of your mandatory inputs here 33 | with: 34 | myInput: world 35 | ``` 36 | 37 | ### Inputs 38 | 39 | | Input | Description | 40 | |------------------------------------------------------|-----------------------------------------------| 41 | | `myInput` | An example mandatory input | 42 | | `anotherInput` _(optional)_ | An example optional input | 43 | 44 | ### Outputs 45 | 46 | | Output | Description | 47 | |------------------------------------------------------|-----------------------------------------------| 48 | | `myOutput` | An example output (returns 'Hello world') | 49 | 50 | ## Examples 51 | 52 | > NOTE: People ❤️ cut and paste examples. Be generous with them! 53 | 54 | ### Using the optional input 55 | 56 | This is how to use the optional input. 57 | 58 | ```yaml 59 | with: 60 | myInput: world 61 | anotherInput: optional 62 | ``` 63 | 64 | ### Using outputs 65 | 66 | Show people how to use your outputs in another action. 67 | 68 | ```yaml 69 | steps: 70 | - uses: actions/checkout@master 71 | - name: Run action 72 | id: myaction 73 | 74 | # Put your action name here 75 | uses: me/myaction@master 76 | 77 | # Put an example of your mandatory arguments here 78 | with: 79 | myInput: world 80 | 81 | # Put an example of using your outputs here 82 | - name: Check outputs 83 | run: | 84 | echo "Outputs - ${{ steps.myaction.outputs.myOutput }}" 85 | ``` -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: "Go Container Action Template" 2 | description: "Get started with Go Container actions" 3 | author: "Jacob Tomlinson" 4 | inputs: 5 | myInput: 6 | description: "Input to use" 7 | default: "world" 8 | outputs: 9 | myOutput: 10 | description: "Output from the action" 11 | runs: 12 | using: "docker" 13 | image: "Dockerfile" 14 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | myInput := os.Getenv("INPUT_MYINPUT") 10 | 11 | output := fmt.Sprintf("Hello %s", myInput) 12 | 13 | fmt.Println(fmt.Sprintf(`::set-output name=myOutput::%s`, output)) 14 | } 15 | --------------------------------------------------------------------------------