Skip to content

Commit b33c873

Browse files
liamcervanteowenrumney
authored andcommitted
Initial commit
0 parents  commit b33c873

File tree

14 files changed

+733
-0
lines changed

14 files changed

+733
-0
lines changed

.github/pull_request_template.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
## Checklist
4+
5+
- [ ] [Technical docs](https://github.com/infracost/technical-docs) updated (or not needed)

.github/workflows/lint.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: lint
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
GOPRIVATE: github.com/infracost/*
10+
11+
jobs:
12+
golangci-lint:
13+
runs-on: ubuntu-24.04
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-go@v6
17+
with:
18+
cache: false
19+
go-version-file: go.mod
20+
- uses: infracost/create-github-app-token@v1
21+
id: app-token
22+
with:
23+
app-id: ${{ secrets.INFRACOST_CI_APP_ID }}
24+
private-key: ${{ secrets.INFRACOST_CI_APP_PRIVATE_KEY }}
25+
owner: infracost
26+
repositories: config
27+
- run: |
28+
git config --global url."https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/".insteadOf "https://github.com/"
29+
- name: golangci-lint
30+
uses: golangci/golangci-lint-action@v9
31+
with:
32+
version: v2.10

.github/workflows/release.yml

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
name: release
2+
on:
3+
push:
4+
tags:
5+
- "v*.*.*"
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: "Version to be released (e.g., 1.0.0)"
10+
type: string
11+
required: true
12+
13+
permissions: {}
14+
15+
jobs:
16+
version:
17+
runs-on: ubuntu-24.04
18+
outputs:
19+
version: ${{ steps.version.outputs.VERSION }}
20+
steps:
21+
- id: version
22+
run: |
23+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
24+
RAW_VERSION="${{ github.event.inputs.version }}"
25+
else
26+
RAW_VERSION="${GITHUB_REF#refs/tags/v}"
27+
fi
28+
echo "VERSION=${RAW_VERSION#v}" >> $GITHUB_OUTPUT
29+
30+
draft-release:
31+
runs-on: ubuntu-24.04
32+
needs: version
33+
permissions:
34+
contents: write
35+
steps:
36+
- name: Check for existing release
37+
id: check-release
38+
env:
39+
GH_TOKEN: ${{ github.token }}
40+
VERSION: v${{ needs.version.outputs.version }}
41+
run: |
42+
if gh release view "$VERSION" --repo "${{ github.repository }}" >/dev/null 2>&1; then
43+
echo "EXISTS=true" >> $GITHUB_OUTPUT
44+
else
45+
echo "EXISTS=false" >> $GITHUB_OUTPUT
46+
fi
47+
48+
- name: Create draft release
49+
if: steps.check-release.outputs.EXISTS == 'false'
50+
env:
51+
GH_TOKEN: ${{ github.token }}
52+
VERSION: v${{ needs.version.outputs.version }}
53+
run: |
54+
gh release create "$VERSION" \
55+
--repo "${{ github.repository }}" \
56+
--title "$VERSION" \
57+
--draft
58+
59+
- name: Reset to draft
60+
if: steps.check-release.outputs.EXISTS == 'true'
61+
env:
62+
GH_TOKEN: ${{ github.token }}
63+
VERSION: v${{ needs.version.outputs.version }}
64+
run: |
65+
gh release edit "$VERSION" \
66+
--repo "${{ github.repository }}" \
67+
--draft
68+
69+
build-and-release:
70+
runs-on: ${{ matrix.runner }}
71+
needs: [version, draft-release]
72+
permissions:
73+
contents: write
74+
strategy:
75+
matrix:
76+
include:
77+
- { goos: linux, goarch: amd64, runner: ubuntu-24.04 }
78+
- { goos: linux, goarch: arm64, runner: ubuntu-24.04 }
79+
- { goos: darwin, goarch: amd64, runner: macos-latest }
80+
- { goos: darwin, goarch: arm64, runner: macos-latest }
81+
- { goos: windows, goarch: amd64, runner: ubuntu-24.04 }
82+
- { goos: windows, goarch: arm64, runner: ubuntu-24.04 }
83+
steps:
84+
- uses: actions/checkout@v4
85+
86+
- uses: actions/setup-go@v6
87+
with:
88+
go-version-file: go.mod
89+
cache-dependency-path: go.sum
90+
91+
- uses: infracost/create-github-app-token@v1
92+
id: app-token
93+
with:
94+
app-id: ${{ secrets.INFRACOST_CI_APP_ID }}
95+
private-key: ${{ secrets.INFRACOST_CI_APP_PRIVATE_KEY }}
96+
owner: infracost
97+
repositories: config
98+
permission-contents: read
99+
100+
- run: |
101+
git config --global url."https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/".insteadOf "https://github.com/"
102+
103+
- name: Build
104+
env:
105+
GOPRIVATE: github.com/infracost/*
106+
GOOS: ${{ matrix.goos }}
107+
GOARCH: ${{ matrix.goarch }}
108+
VERSION: ${{ needs.version.outputs.version }}
109+
run: |
110+
SUFFIX=""
111+
if [ "$GOOS" = "windows" ]; then
112+
SUFFIX=".exe"
113+
fi
114+
go build -ldflags "-X github.com/infracost/cli/version.Version=${VERSION}" -o "bin/infracost${SUFFIX}" main.go
115+
116+
- name: Package
117+
env:
118+
VERSION: ${{ needs.version.outputs.version }}
119+
GOOS: ${{ matrix.goos }}
120+
GOARCH: ${{ matrix.goarch }}
121+
run: |
122+
ARCHIVE="infracost_${VERSION}_${GOOS}_${GOARCH}"
123+
mkdir -p dist
124+
if [ "$GOOS" = "windows" ]; then
125+
(cd bin && zip -r "../dist/${ARCHIVE}.zip" "infracost.exe")
126+
else
127+
tar -czf "dist/${ARCHIVE}.tar.gz" -C bin infracost
128+
fi
129+
130+
- name: Upload
131+
env:
132+
GH_TOKEN: ${{ github.token }}
133+
VERSION: v${{ needs.version.outputs.version }}
134+
run: |
135+
gh release upload "$VERSION" ./dist/* \
136+
--repo "${{ github.repository }}" \
137+
--clobber
138+
139+
publish-release:
140+
runs-on: ubuntu-24.04
141+
needs: [version, build-and-release]
142+
permissions:
143+
contents: write
144+
steps:
145+
- name: Publish release
146+
env:
147+
GH_TOKEN: ${{ github.token }}
148+
VERSION: v${{ needs.version.outputs.version }}
149+
run: |
150+
gh release edit "$VERSION" \
151+
--repo "${{ github.repository }}" \
152+
--draft=false

.github/workflows/spelling.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: spelling
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
codespell:
8+
name: Enforce US English
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: Install codespell
14+
run: |
15+
sudo apt-get update
16+
sudo apt-get install -y python3-pip
17+
pip install codespell==2.4.1
18+
19+
- name: Run codespell
20+
run: |
21+
make spelling
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Technical docs check
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize]
6+
7+
jobs:
8+
technical-docs:
9+
uses: infracost/technical-docs/.github/workflows/technical-docs-check.yml@main

.github/workflows/test.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
env:
10+
GOPRIVATE: github.com/infracost/*
11+
12+
jobs:
13+
unit:
14+
name: Unit Tests
15+
runs-on: ubuntu-24.04
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- uses: actions/setup-go@v6
20+
with:
21+
cache: false
22+
go-version-file: go.mod
23+
24+
- uses: actions/cache/restore@v4
25+
with: # we only restore cache, not save it, so that PR changes don't poison it
26+
path: |
27+
~/go/pkg/mod
28+
~/.cache/go-build
29+
key: nonexistent
30+
restore-keys: |
31+
${{ runner.os }}-go-${{ hashFiles('go.mod') }}-
32+
33+
- uses: infracost/create-github-app-token@v1
34+
id: app-token
35+
with:
36+
app-id: ${{ secrets.INFRACOST_CI_APP_ID }}
37+
private-key: ${{ secrets.INFRACOST_CI_APP_PRIVATE_KEY }}
38+
owner: infracost
39+
repositories: config
40+
41+
- run: |
42+
git config --global url."https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/".insteadOf "https://github.com/"
43+
44+
- run: make test
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: update-manifest
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
plugin:
7+
description: "Plugin name (e.g. infracost-parser-plugin)"
8+
required: true
9+
version:
10+
description: "Version tag (e.g. v0.1.0)"
11+
required: true
12+
latest:
13+
description: "Set as latest version"
14+
type: boolean
15+
default: true
16+
workflow_call:
17+
inputs:
18+
plugin:
19+
description: "Plugin name (e.g. infracost-parser-plugin)"
20+
required: true
21+
type: string
22+
version:
23+
description: "Version tag (e.g. v0.1.0)"
24+
required: true
25+
type: string
26+
latest:
27+
description: "Set as latest version"
28+
type: boolean
29+
default: true
30+
31+
permissions:
32+
contents: write
33+
pull-requests: write
34+
35+
jobs:
36+
update-manifest:
37+
name: Update Manifest
38+
runs-on: ubuntu-24.04
39+
steps:
40+
- uses: actions/checkout@v4
41+
42+
- uses: infracost/create-github-app-token@v1
43+
id: app-token
44+
with:
45+
app-id: ${{ secrets.INFRACOST_CI_APP_ID }}
46+
private-key: ${{ secrets.INFRACOST_CI_APP_PRIVATE_KEY }}
47+
owner: "infracost"
48+
repositories: config
49+
permission-contents: read
50+
51+
- uses: actions/setup-go@v6
52+
with:
53+
cache: false
54+
go-version-file: go.mod
55+
56+
- run: |
57+
git config --global url."https://x-access-token:${GH_TOKEN}@github.com/infracost/".insteadOf "https://github.com/infracost/"
58+
go build -o /tmp/update-manifest ./tools/update-manifest
59+
env:
60+
GOPRIVATE: github.com/infracost/config
61+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
62+
63+
- uses: actions/checkout@v4
64+
with:
65+
ref: published
66+
clean: false
67+
68+
- run: /tmp/update-manifest
69+
env:
70+
UPDATE_MANIFEST_PLUGIN: ${{ inputs.plugin }}
71+
UPDATE_MANIFEST_VERSION: ${{ inputs.version }}
72+
UPDATE_MANIFEST_LATEST: ${{ inputs.latest }}
73+
GITHUB_TOKEN: ${{ github.token }}
74+
75+
- run: |
76+
BRANCH="update-manifest/${{ inputs.plugin }}/${{ inputs.version }}"
77+
MESSAGE="Update manifest for ${{ inputs.plugin }} ${{ inputs.version }}"
78+
REPO="${{ github.repository }}"
79+
80+
PARENT_SHA=$(git rev-parse HEAD)
81+
BASE_TREE=$(gh api "repos/$REPO/git/commits/$PARENT_SHA" --jq '.tree.sha')
82+
83+
# Upload the manifest blob
84+
BLOB_SHA=$(gh api "repos/$REPO/git/blobs" \
85+
--method POST \
86+
-f "content=$(base64 -w 0 docs/manifest.json)" \
87+
-f "encoding=base64" \
88+
--jq '.sha')
89+
90+
# Create a tree with the updated manifest
91+
TREE_SHA=$(jq -n \
92+
--arg base_tree "$BASE_TREE" \
93+
--arg blob_sha "$BLOB_SHA" \
94+
'{"base_tree": $base_tree, "tree": [{"path": "docs/manifest.json", "mode": "100644", "type": "blob", "sha": $blob_sha}]}' | \
95+
gh api "repos/$REPO/git/trees" --method POST --input - --jq '.sha')
96+
97+
# Create a signed commit via the API
98+
COMMIT_SHA=$(gh api "repos/$REPO/git/commits" \
99+
--method POST \
100+
-f "message=$MESSAGE" \
101+
-f "tree=$TREE_SHA" \
102+
-f "parents[]=$PARENT_SHA" \
103+
--jq '.sha')
104+
105+
# Create the branch ref pointing to the new commit
106+
gh api "repos/$REPO/git/refs" \
107+
--method POST \
108+
-f "ref=refs/heads/$BRANCH" \
109+
-f "sha=$COMMIT_SHA"
110+
env:
111+
GH_TOKEN: ${{ github.token }}
112+
113+
- run: |
114+
gh pr create \
115+
--base published \
116+
--head "update-manifest/${{ inputs.plugin }}/${{ inputs.version }}" \
117+
--draft \
118+
--title "Update manifest for ${{ inputs.plugin }} ${{ inputs.version }}" \
119+
--body "Automated manifest update for \`${{ inputs.plugin }}\` version \`${{ inputs.version }}\`."
120+
env:
121+
GITHUB_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)