Repository navigation
169 lines (162 loc) · 5.74 KB
/
Copy pathrelease.yml
File metadata and controls
169 lines (162 loc) · 5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Copyright 2026 LedgerForge Contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Release
on:
push:
tags: ['v*']
permissions:
contents: read
jobs:
checks:
uses: ./.github/workflows/go.yml
binaries:
needs: checks
runs-on: ubuntu-latest
strategy:
matrix:
os: [linux, darwin, windows]
arch: [amd64, arm64]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version: '1.26.9'
cache: true
- name: Build both CLIs and archive license notices
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: '0'
run: |
set -euo pipefail
directory="ledgerforge_${GITHUB_REF_NAME}_${GOOS}_${GOARCH}"
mkdir -p "$directory" dist
suffix=''
if [ "$GOOS" = windows ]; then suffix='.exe'; fi
version="${GITHUB_REF_NAME#v}"
build_date="$(git log -1 --format=%cI)"
ldflags="-s -w -X main.version=${version} -X main.commit=${GITHUB_SHA::7} -X main.date=${build_date}"
go build -trimpath -ldflags "$ldflags" -o "$directory/ledgerforge$suffix" ./cmd/ledgerforge
go build -trimpath -ldflags "-s -w -X main.version=${version}" -o "$directory/ledgerforge-mcp$suffix" ./cmd/ledgerforge-mcp
cp LICENSE.md NOTICE.md "$directory/"
if [ "$GOOS" = windows ]; then
zip -r "dist/$directory.zip" "$directory"
else
tar -czf "dist/$directory.tar.gz" "$directory"
fi
- uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.os }}-${{ matrix.arch }}
path: dist/*
if-no-files-found: error
container:
needs: checks
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
digest: ${{ steps.build.outputs.digest }}
steps:
- uses: actions/checkout@v7
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build metadata
id: version
run: |
{
echo "version=${GITHUB_REF_NAME#v}"
echo "commit=${GITHUB_SHA::7}"
echo "date=$(git log -1 --format=%cI)"
} >> "$GITHUB_OUTPUT"
- uses: docker/metadata-action@v5
id: meta
with:
images: ghcr.io/devaccuracy/ledgerforge
# main owns latest; a prerelease tag must never move that alias.
flavor: latest=false
tags: |
type=ref,event=tag
type=semver,pattern={{version}}
- uses: docker/build-push-action@v7
id: build
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
build-args: |
VERSION=${{ steps.version.outputs.version }}
COMMIT=${{ steps.version.outputs.commit }}
BUILD_DATE=${{ steps.version.outputs.date }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
sbom: true
provenance: mode=max
cache-from: type=gha
cache-to: type=gha,mode=max
publish:
needs: [binaries, container]
runs-on: ubuntu-latest
permissions:
contents: write
packages: read
steps:
- uses: actions/checkout@v7
- uses: actions/download-artifact@v4
with:
pattern: binaries-*
merge-multiple: true
path: dist
- name: Source and dependency SBOM
uses: anchore/sbom-action@v0
with:
path: .
format: spdx-json
output-file: dist/ledgerforge-source.spdx.json
upload-artifact: false
upload-release-assets: false
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Container SBOM for the published digest
uses: anchore/sbom-action@v0
with:
image: ghcr.io/devaccuracy/ledgerforge@${{ needs.container.outputs.digest }}
format: spdx-json
output-file: dist/ledgerforge-container.spdx.json
upload-artifact: false
upload-release-assets: false
- name: Create checksums and publish release assets
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
IMAGE_DIGEST: ${{ needs.container.outputs.digest }}
run: |
set -euo pipefail
printf 'ghcr.io/devaccuracy/ledgerforge@%s\n' "$IMAGE_DIGEST" > dist/container-digest.txt
(cd dist && sha256sum -- * > checksums.txt)
.github/scripts/release-notes.sh "${GITHUB_REF_NAME#v}" CHANGELOG.md > release-notes.md
if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then
gh release upload "$GITHUB_REF_NAME" dist/* --clobber
else
options=()
if [[ "$GITHUB_REF_NAME" == *-* ]]; then options+=(--prerelease); fi
gh release create "$GITHUB_REF_NAME" dist/* --verify-tag --title "LedgerForge $GITHUB_REF_NAME" --notes-file release-notes.md "${options[@]}"
fi