|
| 1 | +on: |
| 2 | + release: |
| 3 | + types: [published] |
| 4 | +name: Upload Release Asset |
| 5 | +jobs: |
| 6 | + release: |
| 7 | + name: Upload Release Asset |
| 8 | + runs-on: ubuntu-latest |
| 9 | + steps: |
| 10 | + - name: Install Go |
| 11 | + uses: actions/setup-go@v2 |
| 12 | + with: |
| 13 | + go-version: 1.x |
| 14 | + - name: Checkout repository |
| 15 | + uses: actions/checkout@v2 |
| 16 | + - name: Build binaries |
| 17 | + run: | |
| 18 | + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "mkcert-$(git describe --tags)-linux-amd64" -ldflags "-X main.Version=$(git describe --tags)" |
| 19 | + CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -o "mkcert-$(git describe --tags)-linux-arm" -ldflags "-X main.Version=$(git describe --tags)" |
| 20 | + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o "mkcert-$(git describe --tags)-linux-arm64" -ldflags "-X main.Version=$(git describe --tags)" |
| 21 | + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o "mkcert-$(git describe --tags)-darwin-amd64" -ldflags "-X main.Version=$(git describe --tags)" |
| 22 | + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o "mkcert-$(git describe --tags)-windows-amd64.exe" -ldflags "-X main.Version=$(git describe --tags)" |
| 23 | + - name: Upload release artifacts |
| 24 | + uses: actions/github-script@v3 |
| 25 | + with: |
| 26 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + script: | |
| 28 | + const fs = require("fs").promises; |
| 29 | + const { repo: { owner, repo }, sha } = context; |
| 30 | +
|
| 31 | + const release = await github.repos.getReleaseByTag({ |
| 32 | + owner, repo, |
| 33 | + tag: process.env.GITHUB_REF.replace("refs/tags/", ""), |
| 34 | + }); |
| 35 | + console.log("Release:", { release }); |
| 36 | +
|
| 37 | + for (let file of await fs.readdir(".")) { |
| 38 | + if (!file.startsWith("mkcert-")) continue; |
| 39 | + console.log("Uploading", file); |
| 40 | + await github.repos.uploadReleaseAsset({ |
| 41 | + owner, repo, |
| 42 | + release_id: release.data.id, |
| 43 | + name: file, |
| 44 | + data: await fs.readFile(file), |
| 45 | + }); |
| 46 | + } |
0 commit comments