Merge pull request #46 from alienc0der/cicd #30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and release znnd and libznn | |
on: | |
push: | |
branches: | |
- master | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
jobs: | |
harden_security: | |
name: Harden Security | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | |
- name: Ensure SHA pinned actions | |
uses: zgosalvez/github-actions-ensure-sha-pinned-actions@2d6823da4039243036c86d76f503c84e2ded2517 | |
xgo: | |
needs: harden_security | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | |
- name: Install zip utility | |
run: | | |
sudo apt update | |
sudo apt install -y zip | |
- name: Check Go environment | |
run: | | |
go env | |
- name: Run tests | |
run: | | |
for s in $(go list ./...); do if ! go test -failfast -v -p 1 $s; then exit 1; fi; done | |
# - name: Check for Go vulnerabilities | |
# run: | | |
# go install golang.org/x/vuln/cmd/govulncheck@latest | |
# /home/runner/go/bin/govulncheck -json ./... | |
- name: Build znnd | |
uses: crazy-max/ghaction-xgo@acf46aa99b919eb9ef6bba89dfd13bafa680667f | |
with: | |
xgo_version: "v0.36.0" | |
go_version: 1.24.1 | |
dest: build | |
prefix: znnd | |
pkg: cmd/znnd | |
targets: darwin/arm64,darwin/amd64,windows/amd64,linux/amd64,linux/arm64 | |
v: true | |
x: true | |
ldflags: -s -w | |
buildvcs: false | |
buildmode: default | |
trimpath: true | |
- name: Build libznn | |
uses: crazy-max/ghaction-xgo@acf46aa99b919eb9ef6bba89dfd13bafa680667f | |
with: | |
xgo_version: "v0.36.0" | |
go_version: 1.24.1 | |
dest: build | |
prefix: libznn | |
pkg: cmd/libznn | |
targets: darwin/arm64,darwin/amd64,linux/amd64,linux/arm64 | |
v: true | |
x: true | |
tags: libznn | |
ldflags: -s -w | |
buildvcs: false | |
buildmode: c-shared | |
trimpath: true | |
- name: Build libznn | |
uses: crazy-max/ghaction-xgo@acf46aa99b919eb9ef6bba89dfd13bafa680667f | |
with: | |
xgo_version: "v0.36.0" | |
go_version: 1.24.1 | |
dest: build | |
prefix: libznn | |
pkg: cmd/libznn | |
targets: windows/amd64 | |
v: true | |
x: true | |
tags: libznn | |
ldflags: -s -w | |
buildvcs: false | |
buildmode: c-shared | |
trimpath: true | |
- name: Upload Darwin builds for makefat | |
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 | |
with: | |
name: darwin-bins | |
path: | | |
build/znnd-darwin-amd64 | |
build/znnd-darwin-arm64 | |
build/libznn-darwin-amd64.dylib | |
build/libznn-darwin-arm64.dylib | |
- name: Go back to build directory, remove header files and add execute flag | |
run: | | |
cd build/ | |
rm ./*.h | |
chmod +x ./* | |
- name: Archive files | |
run: | | |
cd build/ | |
for file in *windows*; do zip $(echo $file | rev | cut -d '.' -f2- | rev)".zip" "$file" && rm "$file" ; done && for so in "linux" "darwin"; do for file in *"$so"*; do tar cvzf $(echo $file | rev | cut -d '.' -f2- | rev)".tar.gz" "$file" && rm "$file" ; done; done | |
- name: Generate checksums | |
run: | | |
cd build/ | |
sha256sum * | |
sha256sum * > SHA256CHECKSUMS.txt | |
- name: Upload slice checksums | |
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 | |
with: | |
name: slice-checksums | |
path: build/SHA256CHECKSUMS.txt | |
- name: Set version | |
run: | | |
GOZENON=$(cat metadata/version.go | grep Version | awk -F '"' '{print $2}') | |
echo "GOZENON_VERSION=$GOZENON" >> $GITHUB_ENV | |
- name: Upload files to a GitHub release | |
uses: svenstaro/upload-release-action@04733e069f2d7f7f0b4aebc4fbdbce8613b03ccd | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: build/* | |
release_name: ${{ env.GOZENON_VERSION }} | |
tag: ${{ env.GOZENON_VERSION }}-alphanet | |
file_glob: true | |
overwrite: true | |
body: "" | |
makefat: | |
name: Create universal Darwin binaries | |
needs: xgo | |
runs-on: macos-latest | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | |
- name: Download Darwin slices | |
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 | |
with: | |
name: darwin-bins | |
path: darwin-bins | |
- name: Download slice checksums | |
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 | |
with: | |
name: slice-checksums | |
path: slice-checksums | |
- name: Prepare output dir | |
run: | | |
mkdir -p universal | |
- name: Create universal znnd | |
run: | | |
lipo -create \ | |
darwin-bins/znnd-darwin-amd64 \ | |
darwin-bins/znnd-darwin-arm64 \ | |
-output universal/znnd-darwin-universal | |
- name: Create universal libznn | |
run: | | |
lipo -create \ | |
darwin-bins/libznn-darwin-amd64.dylib \ | |
darwin-bins/libznn-darwin-arm64.dylib \ | |
-output universal/libznn-darwin-universal.dylib | |
- name: Archive files | |
run: | | |
cd universal/ | |
tar -czvf libznn-darwin-universal.tar.gz libznn-darwin-universal.dylib | |
tar -czvf znnd-darwin-universal.tar.gz znnd-darwin-universal | |
rm libznn-darwin-universal.dylib | |
rm znnd-darwin-universal | |
- name: Generate universal checksums | |
run: | | |
cd universal | |
shasum -a 256 * > UNIVERSAL_CHECKSUMS.txt | |
cd .. | |
- name: Merge all checksums | |
run: | | |
cat slice-checksums/SHA256CHECKSUMS.txt universal/UNIVERSAL_CHECKSUMS.txt > SHA256CHECKSUMS.txt | |
rm universal/UNIVERSAL_CHECKSUMS.txt | |
- name: Set version | |
run: | | |
GOZENON=$(grep Version metadata/version.go \ | |
| awk -F '"' '{print $2}') | |
echo "GOZENON_VERSION=$GOZENON" >> $GITHUB_ENV | |
- name: Upload universal Darwin binaries | |
uses: svenstaro/upload-release-action@04733e069f2d7f7f0b4aebc4fbdbce8613b03ccd | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: universal/* | |
release_name: ${{ env.GOZENON_VERSION }} | |
tag: ${{ env.GOZENON_VERSION }}-alphanet | |
overwrite: true | |
file_glob: true | |
body: "" |