-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b01336
commit b917757
Showing
6 changed files
with
228 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: go-render-template-action | ||
description: "Greta (Go REnder Template Action) renders golang templates" | ||
author: fileformat | ||
|
||
branding: | ||
icon: file-plus | ||
color: green | ||
|
||
inputs: | ||
template: | ||
description: Path to template file. | ||
required: true | ||
input: | ||
description: Path to input file or `-` for stdin. Defaults to stdin. | ||
required: false | ||
output: | ||
description: Path to output file. Output to stdout if not specified. | ||
required: false | ||
mode: | ||
description: '`text` or `html` to select which golang template package to use. Defaults to `html`.' | ||
required: false | ||
|
||
runs: | ||
using: docker | ||
image: docker://ghcr.io/fileformat/greta:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: build | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v1 | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set some env vars for the build | ||
run: | | ||
TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%SZ) | ||
echo "COMMIT=${GITHUB_SHA:0:7}" >> $GITHUB_ENV | ||
echo "LASTMOD=${TIMESTAMP}" >> $GITHUB_ENV | ||
echo "VERSION=${GITHUB_SHA:0:7}" >> $GITHUB_ENV | ||
echo "BUILTBY=GithubActions" >> $GITHUB_ENV | ||
echo "IMAGE_NAME=fileformat/greta" >> $GITHUB_ENV | ||
- name: Build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
push: true | ||
tags: | | ||
ghcr.io/${{ env.IMAGE_NAME }}:${{ env.VERSION }} | ||
ghcr.io/${{ env.IMAGE_NAME }}:latest | ||
build-args: | | ||
COMMIT=${{ env.COMMIT }} | ||
LASTMOD=${{ env.LASTMOD }} | ||
VERSION=${{ env.VERSION }} | ||
BUILTBY=${{ env.BUILTBY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
FROM golang:1.22-alpine AS builder | ||
|
||
RUN apk add --no-cache upx | ||
|
||
RUN mkdir /build | ||
ADD . /build/ | ||
WORKDIR /build | ||
ARG COMMIT | ||
ARG LASTMOD | ||
ARG VERSION | ||
ARG BUILTBY | ||
RUN echo "INFO: building for $COMMIT on $LASTMOD" | ||
|
||
ENV GO111MODULE=on \ | ||
CGO_ENABLED=0 \ | ||
GOOS=linux \ | ||
GOARCH=amd64 | ||
|
||
RUN go build \ | ||
-a \ | ||
-ldflags "-s -w -X main.commit=$COMMIT -X main.date=$LASTMOD -X main.version=$VERSION -X main.builtBy=$BUILTBY -extldflags '-static'" \ | ||
-o greta \ | ||
./greta.go \ | ||
&& upx greta | ||
|
||
FROM scratch | ||
COPY --from=builder /build/greta /bin/greta | ||
WORKDIR /bin | ||
ENTRYPOINT ["./greta"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
env GITHUB_ACTIONS=true | ||
|
||
|
||
# all good | ||
env INPUT_INPUT=good_input.json | ||
env INPUT_TEMPLATE=good_template.tmpl | ||
exec greta | ||
|
||
# bad template | ||
env INPUT_INPUT=good_input.json | ||
env INPUT_TEMPLATE=bad_template.tmpl | ||
! exec greta | ||
|
||
# bad input | ||
env INPUT_INPUT=bad_input.json | ||
env INPUT_TEMPLATE=good_template.tmpl | ||
! exec greta | ||
|
||
# both bad | ||
env INPUT_INPUT=bad_input.json | ||
env INPUT_TEMPLATE=bad_template.tmpl | ||
! exec greta | ||
|
||
# template file does not exist | ||
env INPUT_INPUT=good_input.json | ||
env INPUT_TEMPLATE=bogus.tmpl | ||
! exec greta | ||
|
||
# data file does not exist | ||
env INPUT_INPUT=bogus.json | ||
env INPUT_TEMPLATE=good_template.tmpl | ||
! exec greta | ||
|
||
|
||
# text mode | ||
env INPUT_INPUT=good_input.json | ||
env INPUT_TEMPLATE=good_template.tmpl | ||
env INPUT_MODE=text | ||
exec greta | ||
|
||
# html mode | ||
env INPUT_MODE=html | ||
exec greta | ||
|
||
# bad mode | ||
env INPUT_MODE=other | ||
! exec greta | ||
|
||
# output file | ||
env INPUT_MODE=text | ||
env INPUT_OUTPUT=results.txt | ||
exec greta | ||
exists results.txt | ||
|
||
|
||
|
||
-- good_input.json -- | ||
{ "data": "good" } | ||
|
||
-- bad_input.json -- | ||
this is not { json } | ||
|
||
-- good_template.tmpl -- | ||
Value is {{.}} | ||
|
||
-- bad_template.tmpl -- | ||
Value is {{. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters