-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (96 loc) · 3.55 KB
/
Copy pathrelease.yml
File metadata and controls
117 lines (96 loc) · 3.55 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
name: Build and Release
on:
push:
tags:
- "v*" # Trigger the workflow on tags starting with "v"
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, darwin, windows]
goarch: [386, amd64, arm, arm64]
exclude:
# Exclude certain combinations
- goos: darwin
goarch: 386
- goos: darwin
goarch: arm
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22" # Adjust the Go version if necessary
- name: Build binary
run: |
mkdir -p bin
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o bin/csv2json_${{ matrix.goos }}_${{ matrix.goarch }}$([[ ${{ matrix.goos }} == 'windows' ]] && echo .exe || echo '') ./cmd/csv2json/main.go
- name: List files for debug
run: ls -la bin
- name: Move binary to release directory
run: |
mkdir -p release
ls -la release
mv bin/csv2json_${{ matrix.goos }}_${{ matrix.goarch }}* release/
ls -la release
- name: List release directory for debug
run: ls -la release
- name: Upload Release Assets
uses: actions/upload-artifact@v4
with:
name: release-assets-${{ matrix.goos }}-${{ matrix.goarch }}
path: release/
release:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download Release Assets
uses: actions/download-artifact@v4
with:
path: release-assets
pattern: release-assets-*
merge-multiple: true
- name: Create directories for compression
run: mkdir -p release-compressed
- name: Compress Release Assets
run: |
version=${GITHUB_REF#refs/tags/v}
# Set up name mappings
declare -A goos_map=( ["linux"]="linux" ["darwin"]="macos" ["windows"]="windows" )
declare -A goarch_map=( ["386"]="x86" ["amd64"]="x64" ["arm"]="arm" ["arm64"]="arm64" )
# Compress binaries
for file in release-assets/*; do
base_name=$(basename "$file")
echo "Compressing $base_name"
# Extract goos and goarch
parts=(${base_name//_/ })
goos=${parts[1]}
goarch_with_ext=${parts[2]}
goarch=${goarch_with_ext%%.*} # Remove the file extension
friendly_goos=${goos_map[$goos]}
friendly_goarch=${goarch_map[$goarch]}
# Rename the file to csv2json or csv2json.exe
if [[ $goos == "windows" ]]; then
mv "$file" release-assets/csv2json.exe
file="release-assets/csv2json.exe"
else
mv "$file" release-assets/csv2json
file="release-assets/csv2json"
fi
# Use .zip for macOS and Windows, .tar.gz for Linux
if [[ $goos == "windows" || $goos == "darwin" ]]; then
zip_filename="csv2json-${version}-${friendly_goos}-${friendly_goarch}.zip"
zip release-compressed/${zip_filename} -j "$file"
else
tar_filename="csv2json-${version}-${friendly_goos}-${friendly_goarch}.tar.gz"
tar -czvf release-compressed/${tar_filename} -C release-assets csv2json
fi
done
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: release-compressed/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}