Skip to content

Commit f9181e5

Browse files
authored
Update CI/CD workflows to streamline permissions (#6)
* fix: update CI/CD workflows to streamline permissions * fix: refine release workflow to selectively move and copy binaries * refactor: enhance release workflow to check for existing GitHub releases and streamline build process
1 parent 6c89372 commit f9181e5

File tree

2 files changed

+23
-61
lines changed

2 files changed

+23
-61
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ on:
1212

1313
permissions:
1414
contents: read
15-
pull-requests: read
1615
actions: write
1716

1817
jobs:

.github/workflows/release.yml

Lines changed: 23 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
permissions:
1010
contents: write
11+
actions: write
1112

1213
jobs:
1314
extract-version:
@@ -36,77 +37,36 @@ jobs:
3637
3738
- name: Check if release exists
3839
id: check
40+
env:
41+
GH_TOKEN: ${{ github.token }}
3942
run: |
4043
VERSION="${{ steps.version.outputs.version }}"
41-
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
42-
echo "Tag v$VERSION already exists, skipping release"
44+
45+
# Check if GitHub release exists
46+
if gh release view "v$VERSION" >/dev/null 2>&1; then
47+
echo "Release v$VERSION already exists, skipping release"
4348
echo "should_release=false" >> $GITHUB_OUTPUT
44-
else
45-
echo "Tag v$VERSION does not exist, proceeding with release"
46-
echo "should_release=true" >> $GITHUB_OUTPUT
49+
exit 0
4750
fi
4851
52+
echo "Release v$VERSION does not exist, proceeding with release"
53+
echo "should_release=true" >> $GITHUB_OUTPUT
54+
4955
ci:
5056
name: Run CI
5157
needs: extract-version
5258
if: needs.extract-version.outputs.should_release == 'true'
5359
uses: ./.github/workflows/ci.yml
5460

5561
build:
56-
name: Build ${{ matrix.goos }}-${{ matrix.goarch }}
62+
name: Build
5763
needs: [extract-version, ci]
5864
if: needs.extract-version.outputs.should_release == 'true'
59-
runs-on: ubuntu-latest
60-
strategy:
61-
matrix:
62-
include:
63-
- goos: linux
64-
goarch: amd64
65-
- goos: linux
66-
goarch: arm64
67-
- goos: darwin
68-
goarch: amd64
69-
- goos: darwin
70-
goarch: arm64
71-
- goos: windows
72-
goarch: amd64
73-
74-
steps:
75-
- name: Checkout code
76-
uses: actions/checkout@v4
77-
78-
- name: Set up Go
79-
uses: actions/setup-go@v5
80-
with:
81-
go-version: '1.25.1'
82-
cache: true
83-
84-
- name: Build binary
85-
env:
86-
GOOS: ${{ matrix.goos }}
87-
GOARCH: ${{ matrix.goarch }}
88-
CGO_ENABLED: 0
89-
run: |
90-
VERSION="${{ needs.extract-version.outputs.version }}"
91-
EXT=""
92-
[ "$GOOS" = "windows" ] && EXT=".exe"
93-
BINARY_NAME="sym-$GOOS-$GOARCH$EXT"
94-
95-
go build \
96-
-ldflags "-s -w -X main.Version=$VERSION" \
97-
-trimpath \
98-
-o "$BINARY_NAME" \
99-
./cmd/sym
100-
101-
echo "Built $BINARY_NAME"
102-
103-
- name: Upload artifact
104-
uses: actions/upload-artifact@v4
105-
with:
106-
name: sym-${{ matrix.goos }}-${{ matrix.goarch }}
107-
path: sym-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goos == 'windows' && '.exe' || '' }}
108-
if-no-files-found: error
109-
retention-days: 1
65+
uses: ./.github/workflows/build.yml
66+
with:
67+
version: ${{ needs.extract-version.outputs.version }}
68+
upload-artifacts: true
69+
retention-days: 1
11070

11171
release:
11272
name: Create GitHub Release
@@ -126,7 +86,7 @@ jobs:
12686
- name: Prepare release assets
12787
run: |
12888
mkdir -p release-assets
129-
find artifacts -type f -name 'sym-*' -exec mv {} release-assets/ \;
89+
find artifacts -type f \( -name 'sym-darwin-*' -o -name 'sym-linux-*' -o -name 'sym-windows-*' \) -exec mv {} release-assets/ \;
13090
13191
# Verify binary count
13292
BINARY_COUNT=$(ls -1 release-assets/ | wc -l)
@@ -172,10 +132,13 @@ jobs:
172132
- name: Copy binaries to npm package
173133
run: |
174134
mkdir -p npm/bin
175-
find artifacts -type f -name 'sym-*' -exec cp {} npm/bin/ \;
135+
find artifacts -type f \( -name 'sym-*' ! -name '*.js' \) -exec cp {} npm/bin/ \;
136+
137+
# Set executable permissions for Unix binaries
138+
chmod +x npm/bin/sym-darwin-* npm/bin/sym-linux-* 2>/dev/null || true
176139
177140
# Verify binary count
178-
BINARY_COUNT=$(find npm/bin -name 'sym-*' -type f | wc -l)
141+
BINARY_COUNT=$(find npm/bin -name 'sym-*' -type f ! -name '*.js' | wc -l)
179142
echo "Found $BINARY_COUNT binaries in npm/bin/"
180143
181144
if [ "$BINARY_COUNT" -ne 5 ]; then

0 commit comments

Comments
 (0)