-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (112 loc) · 3.9 KB
/
release.yml
File metadata and controls
128 lines (112 loc) · 3.9 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
name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version
id: get_version
run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Generate changelog
id: changelog
run: |
echo "# Release ${GITHUB_REF#refs/tags/}" > RELEASE_NOTES.md
echo "" >> RELEASE_NOTES.md
echo "## Changes" >> RELEASE_NOTES.md
git log $(git describe --tags --abbrev=0 HEAD^)..HEAD --pretty=format:"- %s" >> RELEASE_NOTES.md || echo "- Initial release" >> RELEASE_NOTES.md
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: cmd4coder ${{ steps.get_version.outputs.version }}
body_path: RELEASE_NOTES.md
draft: false
prerelease: false
build-and-upload:
name: Build and Upload Assets
needs: release
runs-on: ubuntu-latest
strategy:
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: windows
goarch: amd64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.19'
- name: Build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: |
VERSION=${{ needs.release.outputs.version }}
BUILD_TIME=$(date -u +%Y-%m-%dT%H:%M:%SZ)
COMMIT_HASH=${GITHUB_SHA::7}
OUTPUT_NAME="cmd4coder-${VERSION}-${{ matrix.goos }}-${{ matrix.goarch }}"
if [ "${{ matrix.goos }}" = "windows" ]; then
OUTPUT_NAME="${OUTPUT_NAME}.exe"
fi
go build \
-ldflags "-s -w -X 'main.Version=${VERSION}' -X 'main.BuildTime=${BUILD_TIME}' -X 'main.CommitHash=${COMMIT_HASH}'" \
-trimpath \
-o "${OUTPUT_NAME}" \
./cmd/cli
# Create archive
if [ "${{ matrix.goos }}" = "windows" ]; then
ARCHIVE_NAME="cmd4coder-${VERSION}-${{ matrix.goos }}-${{ matrix.goarch }}.zip"
zip "${ARCHIVE_NAME}" "${OUTPUT_NAME}"
else
ARCHIVE_NAME="cmd4coder-${VERSION}-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz"
tar -czf "${ARCHIVE_NAME}" "${OUTPUT_NAME}"
fi
# Calculate checksums
sha256sum "${ARCHIVE_NAME}" > "${ARCHIVE_NAME}.sha256"
echo "ARCHIVE_NAME=${ARCHIVE_NAME}" >> $GITHUB_ENV
echo "Built and packaged: ${ARCHIVE_NAME}"
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ./${{ env.ARCHIVE_NAME }}
asset_name: ${{ env.ARCHIVE_NAME }}
asset_content_type: application/octet-stream
- name: Upload Checksum
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ./${{ env.ARCHIVE_NAME }}.sha256
asset_name: ${{ env.ARCHIVE_NAME }}.sha256
asset_content_type: text/plain