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
0 commit comments