From 2962a61792be70a084a1541bb882fecb58e14f5e Mon Sep 17 00:00:00 2001 From: Maxime Le Conte des Floris Date: Mon, 14 Nov 2022 21:39:41 +0100 Subject: [PATCH] ci: init workflows --- .github/workflows/release.yml | 53 +++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 21 ++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..bd82cd0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,53 @@ +name: release + +on: + release: + types: [published] + +jobs: + release: + name: Upload Release Asset + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: ">=1.19.3" + + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Build binaries + run: | + export VERSION=$(git describe --tags) + export CGO_ENABLED=0 + export LDFLAGS="-X 'main.Version=${VERSION}'" + + GOOS=linux GOARCH=amd64 go build -o "owh-${VERSION}-${GOOS}-${GOARCH}" -ldflags ${LDFLAGS} + GOOS=linux GOARCH=arm GOARM=6 go build -o "owh-${VERSION}-${GOOS}-${GOARCH}" -ldflags ${LDFLAGS} + GOOS=linux GOARCH=arm64 go build -o "owh-${VERSION}-${GOOS}-${GOARCH}" -ldflags ${LDFLAGS} + GOOS=darwin GOARCH=amd64 go build -o "owh-${VERSION}-${GOOS}-${GOARCH}" -ldflags ${LDFLAGS} + GOOS=windows GOARCH=amd64 go build -o "owh-${VERSION}-${GOOS}-${GOARCH}.exe" -ldflags ${LDFLAGS} + + - name: Upload release artifacts + uses: actions/github-script@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const fs = require("fs").promises; + const { repo: { owner, repo }, sha } = context; + const release = await github.repos.getReleaseByTag({ + owner, repo, + tag: process.env.GITHUB_REF.replace("refs/tags/", ""), + }); + console.log("Release:", { release }); + for (let file of await fs.readdir(".")) { + if (!file.startsWith("owh-")) continue; + console.log("Uploading", file); + await github.repos.uploadReleaseAsset({ + owner, repo, + release_id: release.data.id, + name: file, + data: await fs.readFile(file), + }); + } diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..94b2813 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,21 @@ +name: test + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: ">=1.19.3" + + - name: Test + run: go test -v -race ./...