Skip to content

Commit 5e55672

Browse files
committed
feat: add auto releases
1 parent ae4174e commit 5e55672

13 files changed

+218
-70
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @vincenthsh

.github/dependabot.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: gomod
4+
directory: "/"
5+
schedule:
6+
interval: weekly
7+
open-pull-requests-limit: 10
8+
labels:
9+
- bot/merge
10+
commit-message:
11+
prefix: "chore: "
12+
- package-ecosystem: "github-actions"
13+
directory: "/"
14+
schedule:
15+
interval: "weekly"
16+
labels:
17+
- bot/merge
18+
commit-message:
19+
prefix: "chore: "
20+
groups:
21+
github-actions:
22+
patterns:
23+
- "*"

.github/pull_request_template.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### Summary
2+
A description of changes or issues addressed by this PR. Provide links to relevant PRs if any.
3+
4+
### Test Plan
5+
Say unittests, or list out steps to verify changes.
6+
7+
### References
8+
(Optional) Additional links to provide more context.

.github/workflows/build.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- master
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-22.04
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-go@v5
12+
with:
13+
go-version-file: go.mod
14+
- name: Confirm it builds
15+
run: make build
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Validates PR title follows conventional commits
2+
on:
3+
pull_request:
4+
types:
5+
- edited
6+
- opened
7+
- synchronize
8+
- reopened
9+
10+
jobs:
11+
conventional_commit_title:
12+
runs-on: ubuntu-22.04
13+
steps:
14+
# source https://github.com/chanzuckerberg/github-actions/blob/cac0ba177b109becac01bc340a3a1547feb40fe5/.github/actions/conventional-commits/action.yml
15+
- uses: actions/github-script@v7
16+
with:
17+
script: |
18+
const validator = /^(chore|feat|fix|revert|docs|style)(\((((PETI|HSENG|SAENG)-[0-9]+)|([a-z-]+))\))?(!)?: (.)+$/
19+
const title = context.payload.pull_request.title
20+
const is_valid = validator.test(title)
21+
22+
if (!is_valid) {
23+
const details = JSON.stringify({
24+
title: title,
25+
valid_syntax: validator.toString(),
26+
})
27+
core.setFailed(`Your pr title doesn't adhere to conventional commits syntax. See more details: ${details}`)
28+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# ref: https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions#common-dependabot-automations
2+
name: Dependabot auto-approve
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
permissions:
9+
# required to set pr to auto merge
10+
pull-requests: write
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
jobs:
15+
dependabot:
16+
runs-on: ubuntu-22.04
17+
if: ${{ github.actor == 'dependabot[bot]' }}
18+
steps:
19+
- name: Dependabot metadata
20+
id: metadata
21+
uses: dependabot/fetch-metadata@v2
22+
- name: Set to Auto Merge
23+
run: |
24+
gh pr merge --auto --squash "$PR_URL"
25+
env:
26+
PR_URL: ${{github.event.pull_request.html_url}}
27+
GITHUB_TOKEN: ${{ secrets.VINCENT_PAT }}
28+
- name: Approve PR
29+
run: |
30+
gh pr review --approve "$PR_URL"
31+
env:
32+
PR_URL: ${{github.event.pull_request.html_url}}
33+
GITHUB_TOKEN: ${{ secrets.VINCENT_PAT }}

.github/workflows/release.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
6+
name: release-please
7+
jobs:
8+
release-please:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: release please
12+
uses: google-github-actions/release-please-action@v4.1.0
13+
id: release
14+
with:
15+
# https://github.com/google-github-actions/release-please-action#github-credentials
16+
token: ${{ secrets.VINCENT_PAT }}
17+
- uses: actions/checkout@v4
18+
# we need to fetch all history and tags
19+
# so we build the proper version
20+
with:
21+
fetch-depth: 0
22+
if: ${{ steps.release.outputs.release_created }}
23+
- uses: actions/setup-go@v5
24+
with:
25+
go-version-file: go.mod
26+
if: ${{ steps.release.outputs.release_created }}
27+
- name: Get main.go
28+
run: make main.go
29+
if: ${{ steps.release.outputs.release_created }}
30+
- name: Run GoReleaser
31+
uses: goreleaser/goreleaser-action@v5
32+
with:
33+
version: latest
34+
args: release --rm-dist
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.VINCENT_PAT }}
37+
if: ${{ steps.release.outputs.release_created }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
/hclfmt
1+
/bin
22
/dist
33
/main.go
4+
.env

.goreleaser.yml

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
builds:
2-
- env:
3-
- CGO_ENABLED=0
2+
- binary: hclwrite
3+
env:
4+
- CGO_ENABLED=0
5+
goos:
6+
- darwin
7+
- linux
8+
goarch:
9+
- amd64
10+
- arm64
11+
ldflags:
12+
- "-w -s -X main.versionStr={{.Version}}"
413
archives:
5-
- format: gz
6-
files:
7-
- none* # do not include README
8-
replacements:
9-
darwin: Darwin
10-
linux: Linux
11-
windows: Windows
12-
386: i386
13-
amd64: x86_64
14-
checksum:
15-
name_template: 'checksums.txt'
16-
snapshot:
17-
name_template: "{{ .Tag }}-next"
18-
changelog:
19-
sort: asc
20-
filters:
21-
exclude:
22-
- '^docs:'
23-
- '^test:'
14+
- format: gz
15+
files:
16+
- none* # do not include README

Makefile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
all: update build
1+
default: build
22

3-
update:
3+
main.go:
44
curl -O https://raw.githubusercontent.com/hashicorp/hcl/hcl2/cmd/hclfmt/main.go
5+
awk '{gsub(/^const versionStr/,"var versionStr")}1' main.go > temp && mv temp main.go
56

6-
build: ## Build binary
7-
go build
7+
build: main.go ## Build binary
8+
go build -o bin/hclfmt
9+
10+
# install goreleaser with
11+
# brew install goreleaser/tap/goreleaser
12+
snapshot: ## Build snapshot using goreleaser (requires goreleaser to be installed)
13+
goreleaser build --snapshot --clean
814

915
help:
1016
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \

0 commit comments

Comments
 (0)