-
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
0 parents
commit de3a524
Showing
10 changed files
with
170 additions
and
0 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,42 @@ | ||
name: GHA Summarizer | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths-ignore: | ||
- "README.md" | ||
- "LICENSE" | ||
env: | ||
image: ghcr.io/${{ github.repository }}/gha-summarizer | ||
|
||
jobs: | ||
test: | ||
permissions: | ||
contents: read | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.ref }} | ||
repository: ${{ github.event.pull_request.head.repo.full_name }} | ||
|
||
- name: Render template | ||
uses: ./ | ||
with: | ||
template: example/template.md | ||
out-file: out.md | ||
|
||
- name: Check if the rendered file is different | ||
run: | | ||
diff --unified ./example/result.md ./out.md | tee diff.txt | ||
if [ -s diff.txt ]; then | ||
echo "The rendered file is different from the template" | ||
exit 1 | ||
fi | ||
- name: Upload diff | ||
if: success() || failure() | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: diff.txt | ||
path: diff.txt |
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,15 @@ | ||
FROM golang:1.23 AS builder | ||
|
||
WORKDIR /workdir | ||
|
||
COPY go.mod ./ | ||
COPY ./main.go ./ | ||
|
||
RUN go build -o gha-summarizer github.com/VOID404/gha-summarizer | ||
|
||
FROM scratch | ||
|
||
WORKDIR /github/workspace | ||
|
||
COPY --from=builder /workdir/gha-summarizer /gha-summarizer | ||
ENTRYPOINT [ "/gha-summarizer" ] |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Wojciech Nawa | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
# GHA Summarizer |
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,15 @@ | ||
name: "GHA Summarizer" | ||
description: "Simple templating for Github Actions" | ||
inputs: | ||
template: | ||
description: "Template to render" | ||
required: true | ||
out-file: | ||
description: "File to write output to" | ||
required: true | ||
runs: | ||
using: docker | ||
image: Dockerfile | ||
args: | ||
- ${{ inputs.template }} | ||
- ${{ inputs.out-file }} |
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,7 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println("Hello, World!") | ||
} |
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,14 @@ | ||
# Sample template | ||
|
||
Generated from `VOID404/gha-summarizer` | ||
|
||
```go | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println("Hello, World!") | ||
} | ||
|
||
``` |
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,7 @@ | ||
# Sample template | ||
|
||
Generated from `{{ env "$GITHUB_REPOSITORY" }}` | ||
|
||
```go | ||
{{ file "./example/code.go"}} | ||
``` |
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,3 @@ | ||
module github.com/VOID404/gha-summarizer | ||
|
||
go 1.23.0 |
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,45 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
"text/template" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 3 { | ||
fmt.Printf("Usage: %s <template file> <output file>\n", os.Args[0]) | ||
os.Exit(1) | ||
} | ||
|
||
tplFile := os.Args[1] | ||
outFile, err := os.OpenFile(os.Args[2], os.O_CREATE|os.O_WRONLY, 0644) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
funcMap := make(map[string]any) | ||
funcMap["file"] = func(name string) string { | ||
data, err := os.ReadFile(name) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return string(data) | ||
} | ||
|
||
funcMap["env"] = func(text string) string { | ||
return os.ExpandEnv(text) | ||
} | ||
|
||
tpl := template.Must( | ||
template.New(path.Base(tplFile)). // | ||
Funcs(funcMap). | ||
ParseFiles(tplFile), | ||
) | ||
|
||
err = tpl.Execute(outFile, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |