-
Notifications
You must be signed in to change notification settings - Fork 15
166 lines (144 loc) · 4.93 KB
/
Copy pathrelease-go.yml
File metadata and controls
166 lines (144 loc) · 4.93 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
name: Release Go
permissions:
contents: write
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag to release (e.g., v0.1.0)'
required: true
type: string
clobber:
description: 'Overwrite existing release assets (--clobber)'
required: false
type: boolean
default: false
push:
tags: ['v*']
jobs:
build:
name: Build All Binaries
uses: ./.github/workflows/build-go.yml
secrets: inherit
upload-assets:
name: Upload Release Assets
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Get version
id: version
env:
INPUT_TAG: ${{ inputs.tag }}
EVENT_NAME: ${{ github.event_name }}
run: |
if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
VERSION="$INPUT_TAG"
else
VERSION="${GITHUB_REF#refs/tags/}"
fi
if [[ -z "$VERSION" ]]; then
echo "ERROR: Could not determine version" >&2
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Release version: $VERSION"
- name: Check if release exists
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.version.outputs.version }}
run: |
if ! gh release view "$VERSION" > /dev/null 2>&1; then
echo "ERROR: Release not found for tag $VERSION" >&2
echo "Create a GitHub release for this tag before running the workflow." >&2
exit 1
fi
echo "Found existing release for $VERSION"
- name: Download all binary artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: bin/
- name: Verify binaries downloaded
run: |
echo "Downloaded binaries:"
ls -lahrt bin/
BINARY_COUNT=$(find bin/ -type f | wc -l)
echo "Total binaries: $BINARY_COUNT"
if [[ "$BINARY_COUNT" -lt 6 ]]; then
echo "ERROR: Expected at least 6 binaries, found $BINARY_COUNT" >&2
exit 1
fi
- name: Create archives
run: |
for platform_dir in bin/terragrunt-ls_*/; do
platform=$(basename "$platform_dir")
if [[ "$platform" == *windows* ]]; then
binary="terragrunt-ls.exe"
(cd "$platform_dir" && zip "../${platform}.zip" "$binary")
else
binary="terragrunt-ls"
chmod +x "${platform_dir}${binary}"
(cd "$platform_dir" && zip "../${platform}.zip" "$binary")
(cd "$platform_dir" && tar -czf "../${platform}.tar.gz" "$binary")
fi
echo "Created archives for $platform"
done
- name: Generate SHA256SUMS
run: |
cd bin
sha256sum *.zip *.tar.gz > SHA256SUMS
echo "SHA256SUMS:"
cat SHA256SUMS
- name: Upload assets to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.version.outputs.version }}
CLOBBER: ${{ github.event_name == 'workflow_dispatch' && inputs.clobber || 'false' }}
run: |
CLOBBER_FLAG=""
if [[ "$CLOBBER" == "true" ]]; then
CLOBBER_FLAG="--clobber"
echo "Overwrite mode enabled"
fi
echo "Uploading assets to release $VERSION..."
cd bin
for file in *.zip *.tar.gz SHA256SUMS; do
echo "Uploading $file..."
gh release upload "$VERSION" "$file" $CLOBBER_FLAG
done
echo "All assets uploaded"
- name: Verify assets uploaded
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.version.outputs.version }}
run: |
ASSETS=$(gh release view "$VERSION" --json 'assets' --jq '.assets[].name')
echo "Release assets:"
echo "$ASSETS"
EXPECTED_FILES=(
"SHA256SUMS"
)
for platform in darwin_amd64 darwin_arm64 linux_amd64 linux_arm64 windows_amd64 windows_arm64; do
bin="terragrunt-ls_${platform}"
EXPECTED_FILES+=("${bin}.zip")
if [[ "$platform" != windows_* ]]; then
EXPECTED_FILES+=("${bin}.tar.gz")
fi
done
MISSING=0
for expected in "${EXPECTED_FILES[@]}"; do
if echo "$ASSETS" | grep -q "^${expected}$"; then
echo "$expected present"
else
echo "MISSING: $expected" >&2
MISSING=1
fi
done
if [[ "$MISSING" -eq 1 ]]; then
echo "ERROR: Some expected assets are missing from the release" >&2
exit 1
fi
echo "All expected assets verified"