Skip to content

Commit 77cd569

Browse files
committed
add github action
1 parent 2d4305d commit 77cd569

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

.github/workflows/release.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0 # Important for git history and changelog generation
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version: "1.24"
24+
cache: true
25+
26+
- name: Install gcx
27+
run: |
28+
go build -o /usr/local/bin/gcx ./cmd/gcx
29+
chmod +x /usr/local/bin/gcx
30+
31+
- name: Build release binaries
32+
run: gcx build --config gcx.release.yaml
33+
34+
- name: Create GitHub Release
35+
run: |
36+
changelog=$(gcx release changelog)
37+
gh release create ${{ github.ref_name }} ./dist/* --notes "$changelog" --title ${{ github.ref_name }}
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

cmd/gcx/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,13 @@ func buildBinaries(cfg *Config) error {
300300
outDir = "dist"
301301
}
302302

303+
// Clean the output directory if it exists
304+
if _, err := os.Stat(outDir); err == nil {
305+
if err := os.RemoveAll(outDir); err != nil {
306+
return fmt.Errorf("failed to clean output directory: %w", err)
307+
}
308+
}
309+
303310
// Create the build directory
304311
if err := os.MkdirAll(outDir, 0o755); err != nil {
305312
return fmt.Errorf("failed to create output directory: %w", err)
@@ -579,6 +586,9 @@ func createArchives(cfg *Config, artifactsDir string) error {
579586
return fmt.Errorf("failed to read artifacts directory: %w", err)
580587
}
581588

589+
// Track which files were archived
590+
archivedFiles := make(map[string]bool)
591+
582592
// Create archives for each file according to configuration
583593
for _, file := range files {
584594
if file.IsDir() {
@@ -627,6 +637,8 @@ func createArchives(cfg *Config, artifactsDir string) error {
627637
if err := createTarGz(filepath.Join(artifactsDir, fileName), archivePath); err != nil {
628638
return fmt.Errorf("failed to create tar.gz archive: %w", err)
629639
}
640+
// Mark the source file as archived
641+
archivedFiles[fileName] = true
630642
// Here you can add support for other archive formats
631643
default:
632644
log.Printf("Unsupported archive format: %s", format)
@@ -635,6 +647,20 @@ func createArchives(cfg *Config, artifactsDir string) error {
635647
}
636648
}
637649

650+
// Remove all source files that were archived
651+
for _, file := range files {
652+
if file.IsDir() {
653+
continue
654+
}
655+
fileName := file.Name()
656+
if archivedFiles[fileName] {
657+
filePath := filepath.Join(artifactsDir, fileName)
658+
if err := os.Remove(filePath); err != nil {
659+
log.Printf("Warning: failed to remove source file %s: %v", filePath, err)
660+
}
661+
}
662+
}
663+
638664
return nil
639665
}
640666

File renamed without changes.

gcx.release.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: 1
2+
out_dir: dist
3+
4+
builds:
5+
- main: ./cmd/gcx
6+
env:
7+
- CGO_ENABLED=0
8+
goos:
9+
- linux
10+
- darwin
11+
goarch:
12+
- amd64
13+
- arm64
14+
flags:
15+
- -trimpath
16+
ldflags:
17+
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
18+
19+
archives:
20+
- formats:
21+
- tar.gz
22+
name_template: "gcx_{{.Version}}_{{.Os}}_{{.Arch}}"

0 commit comments

Comments
 (0)