Skip to content

Commit 00fbef3

Browse files
committed
Update to github Actions
1 parent 6f88015 commit 00fbef3

File tree

2 files changed

+98
-30
lines changed

2 files changed

+98
-30
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Build, Test, and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '[0-9]+.[0-9]+.[0-9]+-prerelease-[0-9]+'
7+
- '[0-9]+.[0-9]+.[0-9]+' # Trigger on semantic version tags (e.g., v1.0.0)
8+
9+
workflow_dispatch: # Allow manual trigger
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
goos: [linux, windows, darwin]
17+
goarch: [amd64, arm64]
18+
steps:
19+
# Step 1: Checkout code
20+
- name: Checkout code
21+
uses: actions/checkout@v3
22+
23+
# Step 2: Set up Go
24+
- name: Set up Go
25+
uses: actions/setup-go@v4
26+
with:
27+
go-version: 1.22
28+
29+
# Step 3: Run Go tests
30+
- name: Run Go tests
31+
run: |
32+
go test ./... -v
33+
34+
# Step 4: Build the Go app for each platform
35+
- name: Build for ${{ matrix.goos }}-${{ matrix.goarch }}
36+
env:
37+
GOOS: ${{ matrix.goos }}
38+
GOARCH: ${{ matrix.goarch }}
39+
run: |
40+
mkdir -p dist
41+
output_name=clair-scanner_${GOOS}-${GOARCH}
42+
[ "$GOOS" = "windows" ] && output_name+=".exe"
43+
go build -o dist/$output_name
44+
45+
# Step 5: Upload binaries as artifacts for inspection
46+
- name: Upload binaries
47+
uses: actions/upload-artifact@v3
48+
with:
49+
name: clair-scanner_${{ matrix.goos }}_${{ matrix.goarch }}
50+
path: dist/
51+
52+
release:
53+
needs: build
54+
runs-on: ubuntu-latest
55+
steps:
56+
# Step 1: Checkout code
57+
- name: Checkout code
58+
uses: actions/checkout@v3
59+
60+
# Step 2: Download build artifacts
61+
- name: Download binaries
62+
uses: actions/download-artifact@v3
63+
with:
64+
path: dist/
65+
66+
- name: Determine if Prerelease
67+
id: prerelease-check
68+
run: |
69+
if [[ "${GITHUB_REF_NAME}" =~ -prerelease-[0-9]+$ ]]; then
70+
echo "is_prerelease=true" >> $GITHUB_ENV
71+
else
72+
echo "is_prerelease=false" >> $GITHUB_ENV
73+
fi
74+
75+
# Step 3: Create GitHub Release
76+
- name: Create Release
77+
uses: softprops/action-gh-release@v2
78+
env:
79+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
with:
81+
tag_name: ${{ github.ref_name }}
82+
name: Release ${{ github.ref_name }}
83+
body: |
84+
Automated release for ${{ github.ref_name }}.
85+
draft: false
86+
prerelease: ${{ env.is_prerelease }}
87+
88+
# Step 4: Upload binaries to the release
89+
- name: Upload Release Assets
90+
run: |
91+
pwd
92+
ls -alh dist/
93+
find dist/ -type f -print0 | while IFS= read -r -d '' file; do
94+
echo "Uploading: $file"
95+
gh release upload "${{ github.ref_name }}" "$file"
96+
done
97+
env:
98+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.travis.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)