Skip to content

Commit a1a4778

Browse files
authored
Add release workflow and changie (#69)
* Add release workflow and changie * add goreleaser ci
1 parent 7cd8220 commit a1a4778

File tree

10 files changed

+226
-18
lines changed

10 files changed

+226
-18
lines changed

.changes/unreleased/.gitkeep

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: NOTES
2+
body: Initial release of `tfplugingen-openapi` CLI for Terraform Provider Code Generation
3+
tech preview
4+
time: 2023-10-10T14:42:58.532948-04:00
5+
custom:
6+
Issue: "68"

.changie.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
changesDir: .changes
2+
unreleasedDir: unreleased
3+
changelogPath: CHANGELOG.md
4+
versionExt: md
5+
versionFormat: '## {{.Version}} ({{.Time.Format "January 02, 2006"}})'
6+
kindFormat: '{{.Kind}}:'
7+
changeFormat: '* {{.Body}} ([#{{.Custom.Issue}}](https://github.com/hashicorp/terraform-plugin-codegen-openapi/issues/{{.Custom.Issue}}))'
8+
custom:
9+
- key: Issue
10+
label: Issue/PR Number
11+
type: int
12+
minInt: 1
13+
kinds:
14+
- label: BREAKING CHANGES
15+
- label: NOTES
16+
- label: FEATURES
17+
- label: ENHANCEMENTS
18+
- label: BUG FIXES
19+
newlines:
20+
afterKind: 1
21+
beforeKind: 1
22+
endOfVersion: 2
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Continuous integration handling for GoReleaser
2+
name: ci-goreleaser
3+
4+
on:
5+
pull_request:
6+
paths:
7+
- .github/workflows/ci-goreleaser.yml
8+
- .goreleaser.yml
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
check:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
18+
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
19+
with:
20+
go-version-file: 'go.mod'
21+
- uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # v5.0.0
22+
with:
23+
args: check

.github/workflows/release.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
versionNumber:
7+
description: 'Release version number (v#.#.#)'
8+
type: string
9+
required: true
10+
11+
permissions:
12+
contents: read # Changelog commit operations use service account PAT
13+
14+
env:
15+
CI_COMMIT_AUTHOR: hc-github-team-tf-provider-devex
16+
CI_COMMIT_EMAIL: [email protected]
17+
18+
jobs:
19+
changelog-version:
20+
runs-on: ubuntu-latest
21+
outputs:
22+
version: ${{ steps.changelog-version.outputs.version }}
23+
steps:
24+
- id: changelog-version
25+
run: echo "version=$(echo "${{ inputs.versionNumber }}" | cut -c 2-)" >> "$GITHUB_OUTPUT"
26+
27+
changelog:
28+
needs: changelog-version
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
33+
with:
34+
fetch-depth: 0
35+
# Avoid persisting GITHUB_TOKEN credentials as they take priority over our service account PAT for `git push` operations
36+
# More details: https://github.com/actions/checkout/blob/b4626ce19ce1106186ddf9bb20e706842f11a7c3/adrs/0153-checkout-v2.md#persist-credentials
37+
persist-credentials: false
38+
- name: Batch changes
39+
uses: miniscruff/changie-action@6dcc2533cac0495148ed4046c438487e4dceaa23 # v2
40+
with:
41+
version: latest
42+
args: batch ${{ needs.changelog-version.outputs.version }}
43+
- name: Merge changes
44+
uses: miniscruff/changie-action@6dcc2533cac0495148ed4046c438487e4dceaa23 # v2
45+
with:
46+
version: latest
47+
args: merge
48+
- name: Git push changelog
49+
run: |
50+
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
51+
git config --global user.email "${{ env.CI_COMMIT_EMAIL }}"
52+
git add .
53+
git commit -a -m "Update changelog"
54+
git push "https://${{ env.CI_COMMIT_AUTHOR }}:${{ secrets.TF_DEVEX_COMMIT_GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
55+
56+
release-tag:
57+
needs: changelog
58+
runs-on: ubuntu-latest
59+
steps:
60+
- name: Checkout
61+
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
62+
with:
63+
fetch-depth: 0
64+
# Default input is the SHA that initially triggered the workflow. As we created a new commit in the previous job,
65+
# to ensure we get the latest commit we use the ref for checkout: 'refs/heads/<branch_name>'
66+
ref: ${{ github.ref }}
67+
# Avoid persisting GITHUB_TOKEN credentials as they take priority over our service account PAT for `git push` operations
68+
# More details: https://github.com/actions/checkout/blob/b4626ce19ce1106186ddf9bb20e706842f11a7c3/adrs/0153-checkout-v2.md#persist-credentials
69+
persist-credentials: false
70+
71+
- name: Git push release tag
72+
run: |
73+
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
74+
git config --global user.email "${{ env.CI_COMMIT_EMAIL }}"
75+
76+
git tag "${{ inputs.versionNumber }}"
77+
git push "https://${{ env.CI_COMMIT_AUTHOR }}:${{ secrets.TF_DEVEX_COMMIT_GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" "${{ inputs.versionNumber }}"
78+
79+
goreleaser:
80+
needs: [ changelog-version, changelog, release-tag ]
81+
runs-on: ubuntu-latest
82+
permissions:
83+
contents: write # Needed for goreleaser to create GitHub release
84+
issues: write # Needed for goreleaser to close associated milestone
85+
steps:
86+
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
87+
with:
88+
ref: ${{ inputs.versionNumber }}
89+
fetch-depth: 0
90+
91+
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
92+
with:
93+
go-version-file: 'go.mod'
94+
95+
- name: Generate Release Notes
96+
run: |
97+
cd .changes
98+
sed -e "1{/# /d;}" -e "2{/^$/d;}" ${{ needs.changelog-version.outputs.version }}.md > /tmp/release-notes.txt
99+
100+
- uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # v5.0.0
101+
env:
102+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
103+
with:
104+
args: release --release-notes /tmp/release-notes.txt --clean

.goreleaser.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
project_name: tfplugingen-openapi
2+
builds:
3+
- main: ./cmd/tfplugingen-openapi
4+
env:
5+
- CGO_ENABLED=0
6+
mod_timestamp: '{{ .CommitTimestamp }}'
7+
flags:
8+
- -trimpath
9+
ldflags:
10+
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
11+
goos:
12+
- windows
13+
- linux
14+
- darwin
15+
goarch:
16+
- amd64
17+
- arm64
18+
binary: '{{ .ProjectName }}'
19+
archives:
20+
- format: zip
21+
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
22+
checksum:
23+
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
24+
algorithm: sha256
25+
milestones:
26+
- close: true
27+
release:

CHANGELOG.md

Whitespace-only changes.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ For more in-depth details about the design and internals of the OpenAPI Provider
1818

1919
### Installation
2020

21-
The CLI tool can be installed with the Go toolchain, via go install:
21+
You install a copy of the binary manually from the [releases](https://github.com/hashicorp/terraform-plugin-codegen-openapi/releases) tab, or install via the Go toolchain:
2222

2323
```shell-session
2424
go install github.com/hashicorp/terraform-plugin-codegen-openapi/cmd/tfplugingen-openapi@latest

cmd/tfplugingen-openapi/main.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"fmt"
88
"io"
99
"os"
10-
"runtime/debug"
1110

1211
"github.com/mattn/go-colorable"
1312
"github.com/mitchellh/cli"
@@ -19,23 +18,11 @@ import (
1918
// https://goreleaser.com/cookbooks/using-main.version/
2019
func main() {
2120
name := "tfplugingen-openapi"
22-
version := name + func() string {
23-
if info, ok := debug.ReadBuildInfo(); ok {
24-
for _, setting := range info.Settings {
25-
if setting.Key == "vcs.revision" {
26-
return fmt.Sprintf(" commit: %s", setting.Value)
27-
}
28-
}
29-
30-
return fmt.Sprintf(" module: %s", info.Main.Version)
31-
}
32-
33-
return " local"
34-
}()
21+
versionOutput := fmt.Sprintf("%s %s", name, getVersion())
3522

3623
os.Exit(runCLI(
3724
name,
38-
version,
25+
versionOutput,
3926
os.Args[1:],
4027
os.Stdin,
4128
colorable.NewColorableStdout(),
@@ -56,7 +43,7 @@ func initCommands(ui cli.Ui) map[string]cli.CommandFactory {
5643
}
5744
}
5845

59-
func runCLI(name, version string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
46+
func runCLI(name, versionOutput string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
6047
ui := &cli.ColoredUi{
6148
ErrorColor: cli.UiColorRed,
6249
WarnColor: cli.UiColorYellow,
@@ -75,7 +62,7 @@ func runCLI(name, version string, args []string, stdin io.Reader, stdout, stderr
7562
Commands: commands,
7663
HelpFunc: cli.BasicHelpFunc(name),
7764
HelpWriter: stderr,
78-
Version: version,
65+
Version: versionOutput,
7966
}
8067
exitCode, err := openAPIGen.Run()
8168
if err != nil {

cmd/tfplugingen-openapi/version.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package main
5+
6+
import (
7+
"fmt"
8+
"runtime/debug"
9+
)
10+
11+
var (
12+
// These vars will be set by goreleaser.
13+
version string
14+
commit string
15+
)
16+
17+
func getVersion() string {
18+
// Prefer global version as it's set by goreleaser via ldflags
19+
// https://goreleaser.com/cookbooks/using-main.version/
20+
if version != "" {
21+
if commit != "" {
22+
version = fmt.Sprintf("%s from commit: %s", version, commit)
23+
}
24+
return version
25+
}
26+
27+
// If not built with goreleaser, check the binary for VCS revision/module version info
28+
if info, ok := debug.ReadBuildInfo(); ok {
29+
for _, setting := range info.Settings {
30+
if setting.Key == "vcs.revision" {
31+
return fmt.Sprintf("commit: %s", setting.Value)
32+
}
33+
}
34+
35+
return fmt.Sprintf("module: %s", info.Main.Version)
36+
}
37+
38+
return "local"
39+
}

0 commit comments

Comments
 (0)