From 047ea9624050b069a617086c247f3d0d6eceba11 Mon Sep 17 00:00:00 2001 From: Matthias Diester Date: Sun, 15 Dec 2024 13:17:59 +0100 Subject: [PATCH] Test `CGO_ENABLED` project setup Test `CGO_ENABLED` project setup. --- .github/workflows/release.yml | 87 +++++++++++++++++++++++++++++++++++ .gitignore | 3 ++ .goreleaser.yml | 13 ++++++ LICENSE | 2 +- README.md | 1 + go.mod | 3 ++ hack/update-formula.sh | 72 +++++++++++++++++++++++++++++ workflows/release.yml | 87 +++++++++++++++++++++++++++++++++++ 8 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 .goreleaser.yml create mode 100644 go.mod create mode 100755 hack/update-formula.sh create mode 100644 workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..546f7ea --- /dev/null +++ b/.github/workflows/release.yml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b03cc8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +dist +playground +*.tar.gz \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..b8f4dea --- /dev/null +++ b/.goreleaser.yml @@ -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 }}' diff --git a/LICENSE b/LICENSE index 2c3bf4a..db93704 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index eecd50a..e116e2c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # playground + Playground project for tests diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..660f27b --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/homeport/playground + +go 1.18 diff --git a/hack/update-formula.sh b/hack/update-formula.sh new file mode 100755 index 0000000..abc176b --- /dev/null +++ b/hack/update-formula.sh @@ -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 <"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 "ID+harbourmaster@users.noreply.github.com" + +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 diff --git a/workflows/release.yml b/workflows/release.yml new file mode 100644 index 0000000..188ee65 --- /dev/null +++ b/workflows/release.yml @@ -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