Skip to content

Commit

Permalink
Add Continuous Integration (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
hertg committed Sep 17, 2022
1 parent 022fcc4 commit e4bf70a
Show file tree
Hide file tree
Showing 14 changed files with 383 additions and 80 deletions.
5 changes: 5 additions & 0 deletions .ci/generate-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

# mkdir -p .debpkg/usr/bin
# mkdir -p .debpkg/usr/lib/egpu-switcher

43 changes: 43 additions & 0 deletions .ci/generate-pkgbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/sh

version=$1
checksum=$2

#### egpu-switcher ####

mkdir -p ./.pkgbuild/egpu-switcher
cp ./.pkg/aur/egpu-switcher/* ./.pkgbuild/egpu-switcher

cat << EOF > ./.pkgbuild/egpu-switcher/PKGBUILD
# Maintainer: hertg <[email protected]>
# This file is generated automatically
_version=$version
_versionWithoutPrefix=${version#v}
_pkgname=egpu-switcher
_pkgver=$(echo $version | sed 's/\([^-]*-g\)/r\1/;s/-/./g')
_source=\${_pkgname}-\${_version}::https://github.com/hertg/egpu-switcher/archive/refs/tags/$version.tar.gz
EOF

cat ./.pkgbuild/egpu-switcher/PKGBUILD.template >> ./.pkgbuild/egpu-switcher/PKGBUILD
rm ./.pkgbuild/egpu-switcher/PKGBUILD.template


#### egpu-switcher-bin ####

mkdir -p ./.pkgbuild/egpu-switcher-bin
cp ./.pkg/aur/egpu-switcher-bin/* ./.pkgbuild/egpu-switcher-bin

cat << EOF > ./.pkgbuild/egpu-switcher-bin/PKGBUILD
# Maintainer: hertg <[email protected]>
# This file is generated automatically
_version=$version
_pkgname=egpu-switcher-bin
_pkgver=$(echo $version | sed 's/\([^-]*-g\)/r\1/;s/-/./g')
_sha256sum=$checksum
_source=\${_pkgname}-\${_pkgver}::https://github.com/hertg/egpu-switcher/releases/download/$version/egpu-switcher-amd64
EOF

cat ./.pkgbuild/egpu-switcher-bin/PKGBUILD.template >> ./.pkgbuild/egpu-switcher-bin/PKGBUILD
rm ./.pkgbuild/egpu-switcher-bin/PKGBUILD.template


72 changes: 72 additions & 0 deletions .github/workflows/aur-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# reusable workflow
name: Publish to AUR

on:
workflow_call:
inputs:
version:
required: true
type: string
secrets:
AUR_USERNAME:
required: true
AUR_EMAIL:
required: true
AUR_PRIVATE_KEY:
required: true

jobs:
pkgbuild:
runs-on: ubuntu-latest
name: Generate AUR PKGBUILD
steps:

- name: Checkout
uses: actions/checkout@v2

- name: Download binary
uses: actions/download-artifact@v3
with:
name: egpu-switcher-amd64
path: ./download

- name: Export Checksum
run: echo "SHA256=$(cat ./download/sha256sum.txt | cut -d' ' -f1)" >> $GITHUB_ENV

- name: Generate PKGBUILDs
run: ./.ci/generate-pkgbuild.sh ${{ inputs.version }} ${{ env.SHA256 }}

- name: Upload egpu-switcher PKGBUILD
uses: actions/upload-artifact@v3
with:
name: egpu-switcher-PKGBUILD
path: ./.pkgbuild/egpu-switcher/*

- name: Upload egpu-switcher-bin PKGBUILD
uses: actions/upload-artifact@v3
with:
name: egpu-switcher-bin-PKGBUILD
path: ./.pkgbuild/egpu-switcher-bin/*

- name: Publish egpu-switcher
uses: KSXGitHub/[email protected]
with:
pkgname: egpu-switcher
pkgbuild: ./.pkgbuild/egpu-switcher/PKGBUILD
force_push: true
commit_username: ${{ secrets.AUR_USERNAME }}
commit_email: ${{ secrets.AUR_EMAIL }}
ssh_private_key: ${{ secrets.AUR_PRIVATE_KEY }}
commit_message: New release via github actions

- name: Publish egpu-switcher-bin
uses: KSXGitHub/[email protected]
with:
pkgname: egpu-switcher-bin
pkgbuild: ./.pkgbuild/egpu-switcher-bin/PKGBUILD
force_push: true
commit_username: ${{ secrets.AUR_USERNAME }}
commit_email: ${{ secrets.AUR_EMAIL }}
ssh_private_key: ${{ secrets.AUR_PRIVATE_KEY }}
commit_message: New release via github actions

44 changes: 5 additions & 39 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,14 @@ on:
- '*'
tags-ignore:
- '*'

jobs:
test:
runs-on: ubuntu-latest
name: Test
strategy:
matrix:
go: [ '1.19' ]
name: Test (Go ${{ matrix.go }})
steps:

- name: Checkout
uses: actions/checkout@v2

- name: Setup go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}

- name: Run linters
run: make lint

- name: Run tests
run: make test

build:
needs: test
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.19' ]
goosarch:
- linux/amd64
- linux/arm64
name: Build (Go ${{ matrix.go }} / Arch ${{ matrix.goosarch }})
steps:

- name: Checkout
uses: actions/checkout@v2

- name: Setup go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
uses: ./.github/workflows/go-test.yml
with:
go-version: ${{ matrix.go }}

- name: Run build
run: make build
31 changes: 31 additions & 0 deletions .github/workflows/github-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# reusable workflow
name: Create Github Release

on:
workflow_call:
inputs:
binary:
type: string
required: true

jobs:
release:
runs-on: ubuntu-latest
name: Release ${{ inputs.binary }}
steps:

- name: Checkout
uses: actions/checkout@v2

- uses: actions/download-artifact@v3
with:
name: ${{ inputs.binary }}
path: ./download

- name: Create Github Release
uses: softprops/action-gh-release@v1
with:
draft: false
files: download/${{ inputs.binary }}
prerelease: ${{ contains(github.ref, '-rc.') }}

52 changes: 52 additions & 0 deletions .github/workflows/go-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# reusable workflow
name: Build

on:
workflow_call:
inputs:
go-version:
required: true
type: string
go-arch:
required: true
type: string
filename:
required: true
type: string

jobs:
build:
runs-on: ubuntu-latest
name: Run build (Go ${{ inputs.go-version }})
env:
GOARCH: ${{ inputs.go-arch }}
BINARY_NAME: ${{ format('{0}-{1}', inputs.filename, inputs.go-arch) }}
ORIGIN: gh
steps:

- name: Checkout
uses: actions/checkout@v2
with:
# without that 'git describe --tags' may result
# in 'fatal: No names found, cannot describe anything.'
# see https://stackoverflow.com/a/71721059/2726733
fetch-depth: 0

- name: Setup go
uses: actions/setup-go@v3
with:
go-version: ${{ inputs.go-version }}
cache: true

- name: Run build
run: make build

- name: Create SHA256 Checksum
run: sha256sum ./bin/${{ env.BINARY_NAME }} > ./bin/sha256sum.txt || exit $?

- name: Upload binary
uses: actions/upload-artifact@v3
with:
name: ${{ env.BINARY_NAME }}
path: ./bin/*

45 changes: 45 additions & 0 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# reusable workflow
name: Test

on:
workflow_call:
inputs:
go-version:
required: true
type: string

jobs:
test:
runs-on: ubuntu-latest
name: Run tests (Go ${{ inputs.go-version }})
steps:

- name: Checkout
uses: actions/checkout@v2

- name: Setup go
uses: actions/setup-go@v3
with:
go-version: ${{ inputs.go-version }}
cache: true

- name: Run tests
run: make test

lint:
runs-on: ubuntu-latest
name: Run linters (Go ${{ inputs.go-version }})
steps:

- name: Checkout
uses: actions/checkout@v2

- name: Setup go
uses: actions/setup-go@v3
with:
go-version: ${{ inputs.go-version }}
cache: true

- name: Run linters
run: make lint

Loading

0 comments on commit e4bf70a

Please sign in to comment.