From 0f6aa6776116f5c79a3c1052ce1e43c574917885 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 | 154 ++++++++++++++++++++++++++++++++++ .gitignore | 2 + .goreleaser.yml | 13 +++ LICENSE | 2 +- README.md | 1 + cmd/playground/main.go | 57 +++++++++++++ go.mod | 12 +++ go.sum | 49 +++++++++++ workflows/release.yml | 87 +++++++++++++++++++ 9 files changed, 376 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 .goreleaser.yml create mode 100644 cmd/playground/main.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..38667d6 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,154 @@ +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 + token: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} + + - name: Download all workflow run artifacts + uses: actions/download-artifact@v4 + with: + path: tarballs + + - name: Update Formula + env: + GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} + run: |+ + #!/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/.gitignore b/.gitignore new file mode 100644 index 0000000..e28e62f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +dist +*.tar.gz 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/cmd/playground/main.go b/cmd/playground/main.go new file mode 100644 index 0000000..a12bf83 --- /dev/null +++ b/cmd/playground/main.go @@ -0,0 +1,57 @@ +package main + +// #include +// +// void hello() { +// printf("Hello, C\n"); +//} +// +import "C" + +import ( + "bytes" + "fmt" + "image" + "image/color" + "image/png" + "io" + + "golang.design/x/clipboard" +) + +func main() { + fmt.Println("Hello, Go") + C.hello() + + if err := mainE(); err != nil { + panic(err.Error()) + } +} + +func mainE() error { + var buf bytes.Buffer + if err := draw(&buf, 1024, 768); err != nil { + return err + } + + _ = clipboard.Write(clipboard.FmtImage, buf.Bytes()) + + return nil +} + +func draw(w io.Writer, width int, height int) error { + upLeft := image.Point{0, 0} + lowRight := image.Point{width, height} + + img := image.NewRGBA(image.Rectangle{upLeft, lowRight}) + + for h := 0; h < height; h++ { + b := 255 - uint8(255.0*(float64(h)/float64(height))) + + for w := 0; w < width; w++ { + img.Set(w, h, color.RGBA{0, 0, b, 0xFF}) + } + } + + return png.Encode(w, img) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..3f8be87 --- /dev/null +++ b/go.mod @@ -0,0 +1,12 @@ +module github.com/homeport/playground + +go 1.22.0 + +require golang.design/x/clipboard v0.7.0 + +require ( + golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 // indirect + golang.org/x/image v0.6.0 // indirect + golang.org/x/mobile v0.0.0-20230301163155-e0f57694e12c // indirect + golang.org/x/sys v0.5.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..738eee2 --- /dev/null +++ b/go.sum @@ -0,0 +1,49 @@ +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.design/x/clipboard v0.7.0 h1:4Je8M/ys9AJumVnl8m+rZnIvstSnYj1fvzqYrU3TXvo= +golang.design/x/clipboard v0.7.0/go.mod h1:PQIvqYO9GP29yINEfsEn5zSQKAz3UgXmZKzDA6dnq2E= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 h1:estk1glOnSVeJ9tdEZZc5mAMDZk5lNJNyJ6DvrBkTEU= +golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.6.0 h1:bR8b5okrPI3g/gyZakLZHeWxAR8Dn5CyxXv1hLH5g/4= +golang.org/x/image v0.6.0/go.mod h1:MXLdDR43H7cDJq5GEGXEVeeNhPgi+YYEQ2pC1byI1x0= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20230301163155-e0f57694e12c h1:Gk61ECugwEHL6IiyyNLXNzmu8XslmRP2dS0xjIYhbb4= +golang.org/x/mobile v0.0.0-20230301163155-e0f57694e12c/go.mod h1:aAjjkJNdrh3PMckS4B10TGS2nag27cbKR1y2BpUxsiY= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 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