summaryrefslogtreecommitdiffhomepage
path: root/.github/workflows/cigocacher.yml
blob: c4dd0c3c509a57d89ca0ef1ff99aa4d481f26e39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Build cigocacher

on:
  # Released on-demand. The commit will be used as part of the tag, so generally
  # prefer to release from main where the commit is stable in linear history.
  workflow_dispatch:

jobs:
  build:
    strategy:
      matrix:
        GOOS: ["linux", "darwin", "windows"]
        GOARCH: ["amd64", "arm64"]
    runs-on: ubuntu-24.04
    env:
      GOOS: "${{ matrix.GOOS }}"
      GOARCH: "${{ matrix.GOARCH }}"
      CGO_ENABLED: "0"
    steps:
    - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
    - name: Build
      run: |
        OUT="cigocacher$(./tool/go env GOEXE)"
        ./tool/go build -o "${OUT}" ./cmd/cigocacher/
        tar -zcf cigocacher-${{ matrix.GOOS }}-${{ matrix.GOARCH }}.tar.gz "${OUT}"

    - uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
      with:
        name: cigocacher-${{ matrix.GOOS }}-${{ matrix.GOARCH }}
        path: cigocacher-${{ matrix.GOOS }}-${{ matrix.GOARCH }}.tar.gz

  release:
    runs-on: ubuntu-24.04
    needs: build
    permissions:
      contents: write
    steps:
      - name: Download all artifacts
        uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
        with:
          pattern: 'cigocacher-*'
          merge-multiple: true
      # This step is a simplified version of actions/create-release and
      # actions/upload-release-asset, which are archived and unmaintained.
      - name: Create release
        uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
        with:
          script: |
            const fs = require('fs');
            const path = require('path');

            const { data: release } = await github.rest.repos.createRelease({
              owner: context.repo.owner,
              repo: context.repo.repo,
              tag_name: `cmd/cigocacher/${{ github.sha }}`,
              name: `cigocacher-${{ github.sha }}`,
              draft: false,
              prerelease: true,
              target_commitish: `${{ github.sha }}`
            });

            const files = fs.readdirSync('.').filter(f => f.endsWith('.tar.gz'));
            
            for (const file of files) {
              await github.rest.repos.uploadReleaseAsset({
                owner: context.repo.owner,
                repo: context.repo.repo,
                release_id: release.id,
                name: file,
                data: fs.readFileSync(file)
              });
              console.log(`Uploaded ${file}`);
            }