Skip to content

Commit d03f0cb

Browse files
committed
fix: update snap workflow and configuration for better GitHub Actions compatibility
1 parent f6be94a commit d03f0cb

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

.github/workflows/snap.yml

+34-14
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,58 @@ on:
77

88
jobs:
99
build-and-publish:
10-
runs-on: ubuntu-latest
10+
runs-on: ubuntu-20.04
1111
steps:
1212
- name: Checkout
1313
uses: actions/checkout@v4
1414
with:
1515
fetch-depth: 0
1616

17-
- name: Install Snapcraft
18-
uses: samuelmeuli/action-snapcraft@v2
17+
- name: Set up Go
18+
uses: actions/setup-go@v4
1919
with:
20-
use_lxd: true
21-
20+
go-version: '1.23'
21+
cache: true
22+
2223
- name: Extract version from tag
2324
id: get_version
2425
run: |
2526
VERSION=${GITHUB_REF#refs/tags/v}
26-
echo "VERSION=$VERSION" >> $GITHUB_ENV
27+
echo "version=$VERSION" >> $GITHUB_OUTPUT
2728
echo "The version is $VERSION"
2829
30+
- name: Setup Snapcraft
31+
run: |
32+
sudo apt-get update
33+
sudo apt-get install -y snapd
34+
sudo snap install snapcraft --classic
35+
2936
- name: Update version in snapcraft.yaml
3037
run: |
31-
sed -i "s/^version: git/version: $VERSION/" snap/snapcraft.yaml
38+
sed -i "s/^version: git/version: ${{ steps.get_version.outputs.version }}/" snap/snapcraft.yaml
3239
cat snap/snapcraft.yaml
3340
41+
- name: Install LXD
42+
run: |
43+
sudo snap install lxd
44+
sudo lxd init --auto
45+
3446
- name: Build snap
3547
run: |
36-
snapcraft
48+
# Use LXD as the build environment
49+
sudo snap install snapcraft --classic
50+
SNAPCRAFT_BUILD_ENVIRONMENT=lxd snapcraft
3751
38-
- name: Publish snap
39-
uses: snapcore/action-publish@v1
40-
env:
41-
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_TOKEN }}
52+
- name: Upload snap as artifact
53+
uses: actions/upload-artifact@v3
4254
with:
43-
snap: httpprobe_*.snap
44-
release: stable
55+
name: httpprobe-snap
56+
path: ./*.snap
57+
58+
- name: Publish snap
59+
if: startsWith(github.ref, 'refs/tags/v')
60+
run: |
61+
echo "${{ secrets.SNAPCRAFT_TOKEN }}" > snapcraft.login
62+
snapcraft login --with snapcraft.login
63+
snapcraft upload --release=stable *.snap
64+
rm -f snapcraft.login

snap/snapcraft.yaml

+4-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ parts:
1313
httpprobe:
1414
plugin: go
1515
source: .
16-
source-type: local
17-
build-snaps:
18-
- go
16+
go-buildtags: [static]
17+
build-environment:
18+
- CGO_ENABLED: "0"
1919
override-build: |
20-
craftctl default
21-
cd $CRAFT_PART_SRC
22-
go build -o $CRAFT_PART_INSTALL/bin/httpprobe ./cmd/main.go
20+
go build -o $SNAPCRAFT_PART_INSTALL/bin/httpprobe ./cmd/main.go
2321
2422
apps:
2523
httpprobe:

0 commit comments

Comments
 (0)