Skip to content

Commit e4bf70a

Browse files
authored
Add Continuous Integration (#89)
1 parent 022fcc4 commit e4bf70a

File tree

14 files changed

+383
-80
lines changed

14 files changed

+383
-80
lines changed

.ci/generate-deb.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
# mkdir -p .debpkg/usr/bin
4+
# mkdir -p .debpkg/usr/lib/egpu-switcher
5+

.ci/generate-pkgbuild.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/sh
2+
3+
version=$1
4+
checksum=$2
5+
6+
#### egpu-switcher ####
7+
8+
mkdir -p ./.pkgbuild/egpu-switcher
9+
cp ./.pkg/aur/egpu-switcher/* ./.pkgbuild/egpu-switcher
10+
11+
cat << EOF > ./.pkgbuild/egpu-switcher/PKGBUILD
12+
# Maintainer: hertg <aur@her.tg>
13+
# This file is generated automatically
14+
_version=$version
15+
_versionWithoutPrefix=${version#v}
16+
_pkgname=egpu-switcher
17+
_pkgver=$(echo $version | sed 's/\([^-]*-g\)/r\1/;s/-/./g')
18+
_source=\${_pkgname}-\${_version}::https://github.com/hertg/egpu-switcher/archive/refs/tags/$version.tar.gz
19+
EOF
20+
21+
cat ./.pkgbuild/egpu-switcher/PKGBUILD.template >> ./.pkgbuild/egpu-switcher/PKGBUILD
22+
rm ./.pkgbuild/egpu-switcher/PKGBUILD.template
23+
24+
25+
#### egpu-switcher-bin ####
26+
27+
mkdir -p ./.pkgbuild/egpu-switcher-bin
28+
cp ./.pkg/aur/egpu-switcher-bin/* ./.pkgbuild/egpu-switcher-bin
29+
30+
cat << EOF > ./.pkgbuild/egpu-switcher-bin/PKGBUILD
31+
# Maintainer: hertg <aur@her.tg>
32+
# This file is generated automatically
33+
_version=$version
34+
_pkgname=egpu-switcher-bin
35+
_pkgver=$(echo $version | sed 's/\([^-]*-g\)/r\1/;s/-/./g')
36+
_sha256sum=$checksum
37+
_source=\${_pkgname}-\${_pkgver}::https://github.com/hertg/egpu-switcher/releases/download/$version/egpu-switcher-amd64
38+
EOF
39+
40+
cat ./.pkgbuild/egpu-switcher-bin/PKGBUILD.template >> ./.pkgbuild/egpu-switcher-bin/PKGBUILD
41+
rm ./.pkgbuild/egpu-switcher-bin/PKGBUILD.template
42+
43+

.github/workflows/aur-release.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# reusable workflow
2+
name: Publish to AUR
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
version:
8+
required: true
9+
type: string
10+
secrets:
11+
AUR_USERNAME:
12+
required: true
13+
AUR_EMAIL:
14+
required: true
15+
AUR_PRIVATE_KEY:
16+
required: true
17+
18+
jobs:
19+
pkgbuild:
20+
runs-on: ubuntu-latest
21+
name: Generate AUR PKGBUILD
22+
steps:
23+
24+
- name: Checkout
25+
uses: actions/checkout@v2
26+
27+
- name: Download binary
28+
uses: actions/download-artifact@v3
29+
with:
30+
name: egpu-switcher-amd64
31+
path: ./download
32+
33+
- name: Export Checksum
34+
run: echo "SHA256=$(cat ./download/sha256sum.txt | cut -d' ' -f1)" >> $GITHUB_ENV
35+
36+
- name: Generate PKGBUILDs
37+
run: ./.ci/generate-pkgbuild.sh ${{ inputs.version }} ${{ env.SHA256 }}
38+
39+
- name: Upload egpu-switcher PKGBUILD
40+
uses: actions/upload-artifact@v3
41+
with:
42+
name: egpu-switcher-PKGBUILD
43+
path: ./.pkgbuild/egpu-switcher/*
44+
45+
- name: Upload egpu-switcher-bin PKGBUILD
46+
uses: actions/upload-artifact@v3
47+
with:
48+
name: egpu-switcher-bin-PKGBUILD
49+
path: ./.pkgbuild/egpu-switcher-bin/*
50+
51+
- name: Publish egpu-switcher
52+
uses: KSXGitHub/github-actions-deploy-aur@v2.5.0
53+
with:
54+
pkgname: egpu-switcher
55+
pkgbuild: ./.pkgbuild/egpu-switcher/PKGBUILD
56+
force_push: true
57+
commit_username: ${{ secrets.AUR_USERNAME }}
58+
commit_email: ${{ secrets.AUR_EMAIL }}
59+
ssh_private_key: ${{ secrets.AUR_PRIVATE_KEY }}
60+
commit_message: New release via github actions
61+
62+
- name: Publish egpu-switcher-bin
63+
uses: KSXGitHub/github-actions-deploy-aur@v2.5.0
64+
with:
65+
pkgname: egpu-switcher-bin
66+
pkgbuild: ./.pkgbuild/egpu-switcher-bin/PKGBUILD
67+
force_push: true
68+
commit_username: ${{ secrets.AUR_USERNAME }}
69+
commit_email: ${{ secrets.AUR_EMAIL }}
70+
ssh_private_key: ${{ secrets.AUR_PRIVATE_KEY }}
71+
commit_message: New release via github actions
72+

.github/workflows/ci.yml

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,14 @@ on:
66
- '*'
77
tags-ignore:
88
- '*'
9+
910
jobs:
1011
test:
11-
runs-on: ubuntu-latest
12+
name: Test
1213
strategy:
1314
matrix:
1415
go: [ '1.19' ]
15-
name: Test (Go ${{ matrix.go }})
16-
steps:
17-
18-
- name: Checkout
19-
uses: actions/checkout@v2
20-
21-
- name: Setup go
22-
uses: actions/setup-go@v2
23-
with:
24-
go-version: ${{ matrix.go }}
25-
26-
- name: Run linters
27-
run: make lint
28-
29-
- name: Run tests
30-
run: make test
31-
32-
build:
33-
needs: test
34-
runs-on: ubuntu-latest
35-
strategy:
36-
matrix:
37-
go: [ '1.19' ]
38-
goosarch:
39-
- linux/amd64
40-
- linux/arm64
41-
name: Build (Go ${{ matrix.go }} / Arch ${{ matrix.goosarch }})
42-
steps:
43-
44-
- name: Checkout
45-
uses: actions/checkout@v2
46-
47-
- name: Setup go
48-
uses: actions/setup-go@v2
49-
with:
50-
go-version: ${{ matrix.go }}
16+
uses: ./.github/workflows/go-test.yml
17+
with:
18+
go-version: ${{ matrix.go }}
5119

52-
- name: Run build
53-
run: make build
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# reusable workflow
2+
name: Create Github Release
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
binary:
8+
type: string
9+
required: true
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
name: Release ${{ inputs.binary }}
15+
steps:
16+
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
20+
- uses: actions/download-artifact@v3
21+
with:
22+
name: ${{ inputs.binary }}
23+
path: ./download
24+
25+
- name: Create Github Release
26+
uses: softprops/action-gh-release@v1
27+
with:
28+
draft: false
29+
files: download/${{ inputs.binary }}
30+
prerelease: ${{ contains(github.ref, '-rc.') }}
31+

.github/workflows/go-build.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# reusable workflow
2+
name: Build
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
go-version:
8+
required: true
9+
type: string
10+
go-arch:
11+
required: true
12+
type: string
13+
filename:
14+
required: true
15+
type: string
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
name: Run build (Go ${{ inputs.go-version }})
21+
env:
22+
GOARCH: ${{ inputs.go-arch }}
23+
BINARY_NAME: ${{ format('{0}-{1}', inputs.filename, inputs.go-arch) }}
24+
ORIGIN: gh
25+
steps:
26+
27+
- name: Checkout
28+
uses: actions/checkout@v2
29+
with:
30+
# without that 'git describe --tags' may result
31+
# in 'fatal: No names found, cannot describe anything.'
32+
# see https://stackoverflow.com/a/71721059/2726733
33+
fetch-depth: 0
34+
35+
- name: Setup go
36+
uses: actions/setup-go@v3
37+
with:
38+
go-version: ${{ inputs.go-version }}
39+
cache: true
40+
41+
- name: Run build
42+
run: make build
43+
44+
- name: Create SHA256 Checksum
45+
run: sha256sum ./bin/${{ env.BINARY_NAME }} > ./bin/sha256sum.txt || exit $?
46+
47+
- name: Upload binary
48+
uses: actions/upload-artifact@v3
49+
with:
50+
name: ${{ env.BINARY_NAME }}
51+
path: ./bin/*
52+

.github/workflows/go-test.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# reusable workflow
2+
name: Test
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
go-version:
8+
required: true
9+
type: string
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
name: Run tests (Go ${{ inputs.go-version }})
15+
steps:
16+
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
20+
- name: Setup go
21+
uses: actions/setup-go@v3
22+
with:
23+
go-version: ${{ inputs.go-version }}
24+
cache: true
25+
26+
- name: Run tests
27+
run: make test
28+
29+
lint:
30+
runs-on: ubuntu-latest
31+
name: Run linters (Go ${{ inputs.go-version }})
32+
steps:
33+
34+
- name: Checkout
35+
uses: actions/checkout@v2
36+
37+
- name: Setup go
38+
uses: actions/setup-go@v3
39+
with:
40+
go-version: ${{ inputs.go-version }}
41+
cache: true
42+
43+
- name: Run linters
44+
run: make lint
45+

0 commit comments

Comments
 (0)