release.yml 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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=darwin GOARCH=arm64 go build -o "mkcert-$(git describe --tags)-darwin-arm64" -ldflags "-X main.Version=$(git describe --tags)"
  23. CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o "mkcert-$(git describe --tags)-windows-amd64.exe" -ldflags "-X main.Version=$(git describe --tags)"
  24. - name: Upload release artifacts
  25. uses: actions/github-script@v3
  26. with:
  27. github-token: ${{ secrets.GITHUB_TOKEN }}
  28. script: |
  29. const fs = require("fs").promises;
  30. const { repo: { owner, repo }, sha } = context;
  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. for (let file of await fs.readdir(".")) {
  37. if (!file.startsWith("mkcert-")) continue;
  38. console.log("Uploading", file);
  39. await github.repos.uploadReleaseAsset({
  40. owner, repo,
  41. release_id: release.data.id,
  42. name: file,
  43. data: await fs.readFile(file),
  44. });
  45. }