aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/release.yml
blob: 4bfd913a0cca4b85259c23d09b8afe53d10a698c (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: Release

on:
  workflow_dispatch:
  push:
    tags:
      - "v*"

permissions:
  contents: write

jobs:
  build:
    name: Build (${{ matrix.os }})
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            binary: pomoru
            archive: pomoru-linux-x86_64.tar.gz

          - os: windows-latest
            binary: pomoru.exe
            archive: pomoru-windows-x86_64.zip

          - os: macos-latest
            binary: pomoru
            archive: pomoru-macos-arm64.zip

    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Build
        run: cargo build --release

      - name: Package (Linux)
        if: runner.os == 'Linux'
        shell: bash
        run: |
          mkdir package

          cp target/release/${{ matrix.binary }} package/
          cp README.md package/
          cp LICENSE package/

          tar -czf ${{ matrix.archive }} -C package .

      - name: Package (macOS)
        if: runner.os == 'macOS'
        shell: bash
        run: |
          mkdir package

          cp target/release/${{ matrix.binary }} package/
          cp README.md package/
          cp LICENSE package/

          cd package
          zip -r ../${{ matrix.archive }} .
          cd ..

      - name: Package (Windows)
        if: runner.os == 'Windows'
        shell: pwsh
        run: |
          New-Item -ItemType Directory -Path package -Force

          Copy-Item target/release/${{ matrix.binary }} package/
          Copy-Item README.md package/
          Copy-Item LICENSE package/

          Compress-Archive `
            -Path package/* `
            -DestinationPath ${{ matrix.archive }}

      - name: Upload Build Artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.archive }}
          path: ${{ matrix.archive }}

  release:
    name: Create Release
    needs: build

    if: startsWith(github.ref, 'refs/tags/')

    runs-on: ubuntu-latest

    steps:
      - name: Download Artifacts
        uses: actions/download-artifact@v4
        with:
          path: release-assets

      - name: Flatten Artifacts
        run: |
          mkdir final

          find release-assets -type f \
            \( -name "*.tar.gz" -o -name "*.zip" \) \
            -exec cp {} final/ \;

      - name: Generate SHA256 Checksums
        run: |
          cd final
          sha256sum * > sha256sums.txt

      - name: Create Draft Release
        uses: softprops/action-gh-release@v2
        with:
          draft: true
          generate_release_notes: true
          files: |
            final/*