Skip to content

Commit

Permalink
Test CGO_ENABLED project setup
Browse files Browse the repository at this point in the history
Test `CGO_ENABLED` project setup.
  • Loading branch information
HeavyWombat committed Dec 15, 2024
1 parent 179aca7 commit 047ea96
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 1 deletion.
87 changes: 87 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, macos-13]

runs-on: ${{ matrix.os }}
permissions:
contents: write
pull-requests: write
repository-projects: write

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: stable

- name: Build project
env:
CGO_ENABLED: "1"
run: |
go build \
-trimpath \
-ldflags="-s -w" \
-o playground \
cmd/playground/main.go
- name: Upload release asset
env:
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
SYSTEM_UNAME="$(uname | tr '[:upper:]' '[:lower:]')"
SYSTEM_ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')"
DIR_NAME="$(basename $(pwd))"
CURRENT_TAG="$(git describe --exact-match --tags)"
TARBALL_NAME="${DIR_NAME}_${CURRENT_TAG#v}_${SYSTEM_UNAME}_${SYSTEM_ARCH}.tar.gz"
tar -cf - LICENSE README.md playground | gzip --best >"$TARBALL_NAME"
gh release upload "$CURRENT_TAG" "$TARBALL_NAME"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: tarball-${{ matrix.os }}
path: |
*.tar.gz
homebrew_update:
needs: build

runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Checkout Homebrew tap repository
uses: actions/checkout@v3
with:
repository: homeport/homebrew-tap
path: homebrew-tap

- name: Checkout project repository
uses: actions/checkout@v3
with:
path: repo

- name: Download all workflow run artifacts
uses: actions/download-artifact@v4
with:
path: tarballs

- name: TAE
env:
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: repo/hack/update-formula.sh
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
playground
*.tar.gz
13 changes: 13 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
project_name: playground
version: 2

builds:
- env:
- CGO_ENABLED=1
main: ./cmd/playground/main.go
flags:
- -trimpath
ldflags:
- -s -w
mod_timestamp: '{{ .CommitTimestamp }}'
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 homeport
Copyright (c) 2024 The Homeport Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# playground

Playground project for tests
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/homeport/playground

go 1.18
72 changes: 72 additions & 0 deletions hack/update-formula.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash

set -euo pipefail

BASEDIR="$(pwd)"

REPO_NAME=homeport/playground
LATEST_RELEASE="$(gh --repo ${REPO_NAME} release list --json tagName,isLatest | jq --raw-output '.[] | select(.isLatest) | .tagName')"

DARWIN_AMD64_SHA="$(sha256sum "$BASEDIR/tarballs/tarball-macos-13/playground_${LATEST_RELEASE#v}_darwin_amd64.tar.gz" | awk '{print $1}')"
DARWIN_ARM64_SHA="$(sha256sum "$BASEDIR/tarballs/tarball-macos-latest/playground_${LATEST_RELEASE#v}_darwin_arm64.tar.gz" | awk '{print $1}')"
LINUX_AMD64_SHA="$(sha256sum "$BASEDIR/tarballs/tarball-ubuntu-latest/playground_${LATEST_RELEASE#v}_linux_amd64.tar.gz" | awk '{print $1}')"

pushd "$BASEDIR/homebrew-tap/" >/dev/null

cat <<EOF >"HomebrewFormula/playground.rb"
# This file was generated by $0. DO NOT EDIT.
class Playground < Formula
desc "Playground project."
homepage "https://github.com/${REPO_NAME}"
version "${LATEST_RELEASE#v}"
license "MIT"
on_macos do
on_intel do
url "https://github.com/${REPO_NAME}/releases/download/v${LATEST_RELEASE#v}/playground_${LATEST_RELEASE#v}_darwin_amd64.tar.gz", using: CurlDownloadStrategy
sha256 "${DARWIN_AMD64_SHA}"
def install
bin.install "playground"
end
end
on_arm do
url "https://github.com/${REPO_NAME}/releases/download/v${LATEST_RELEASE#v}/playground_${LATEST_RELEASE#v}_darwin_arm64.tar.gz", using: CurlDownloadStrategy
sha256 "${DARWIN_ARM64_SHA}"
def install
bin.install "playground"
end
end
end
on_linux do
on_intel do
if Hardware::CPU.is_64_bit?
url "https://github.com/${REPO_NAME}/releases/download/v${LATEST_RELEASE#v}/playground_${LATEST_RELEASE#v}_linux_amd64.tar.gz", using: CurlDownloadStrategy
sha256 "${LINUX_AMD64_SHA}"
def install
bin.install "playground"
end
end
end
end
test do
system "#{bin}/playground"
end
end
EOF

git config --global user.name "Harbourmaster"
git config --global user.email "[email protected]"

git add HomebrewFormula/playground.rb
git commit \
--message "Update playground to \`$LATEST_RELEASE\`" \
--message "" \
--message "Update playground formula to \`$LATEST_RELEASE\`."
git push origin HEAD

popd >/dev/null
87 changes: 87 additions & 0 deletions workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, macos-13]

runs-on: ${{ matrix.os }}
permissions:
contents: write
pull-requests: write
repository-projects: write

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: stable

- name: Build project
env:
CGO_ENABLED: "1"
run: |
go build \
-trimpath \
-ldflags="-s -w" \
-o playground \
cmd/playground/main.go
- name: Upload release asset
env:
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
SYSTEM_UNAME="$(uname | tr '[:upper:]' '[:lower:]')"
SYSTEM_ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')"
DIR_NAME="$(basename $(pwd))"
CURRENT_TAG="$(git describe --exact-match --tags)"
TARBALL_NAME="${DIR_NAME}_${CURRENT_TAG#v}_${SYSTEM_UNAME}_${SYSTEM_ARCH}.tar.gz"
tar -cf - LICENSE README.md playground | gzip --best >"$TARBALL_NAME"
gh release upload "$CURRENT_TAG" "$TARBALL_NAME"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: tarball-${{ matrix.os }}
path: |
*.tar.gz
homebrew_update:
needs: build

runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Checkout Homebrew tap repository
uses: actions/checkout@v3
with:
repository: homeport/homebrew-tap
path: homebrew-tap

- name: Checkout project repository
uses: actions/checkout@v3
with:
path: repo

- name: Download all workflow run artifacts
uses: actions/download-artifact@v4
with:
path: tarballs

- name: Update Homebrew Formula
env:
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: repo/hack/update-formula.sh

0 comments on commit 047ea96

Please sign in to comment.