Krolyxon
Tag v0.3.0

Branches

Tags

Refs →

bench51.githubworkflowsrelease.yml

178 lines · 6.4 KB · YAML

1name: Release
2
3# Pushing a tag vX.Y.Z (matching the version in Cargo.toml) builds bench51
4# for every target, publishes a GitHub release with the archives, checksums
5# and the CHANGELOG.md section as notes, then installs it with the one-line
6# installers on each OS. Pull requests that touch the release machinery get
7# a dry run: everything except publishing.
8
9on:
10 push:
11 tags: ['v*']
12 pull_request:
13 paths:
14 - .github/workflows/release.yml
15 - install.sh
16 - install.ps1
17 workflow_dispatch:
18
19permissions:
20 contents: read
21
22env:
23 CARGO_TERM_COLOR: always
24
25jobs:
26 build:
27 name: ${{ matrix.target }}
28 strategy:
29 fail-fast: false
30 matrix:
31 include:
32 # 22.04 keeps the glibc requirement low for older distributions.
33 - { target: x86_64-unknown-linux-gnu, os: ubuntu-22.04 }
34 - { target: aarch64-unknown-linux-gnu, os: ubuntu-22.04-arm }
35 - { target: x86_64-pc-windows-msvc, os: windows-latest }
36 - { target: aarch64-apple-darwin, os: macos-latest }
37 # Cross-compiled on Apple silicon, so it can't be run here.
38 - { target: x86_64-apple-darwin, os: macos-latest, cross: true }
39 runs-on: ${{ matrix.os }}
40 steps:
41 - uses: actions/checkout@v7
42
43 - name: Check the tag matches Cargo.toml
44 if: startsWith(github.ref, 'refs/tags/v')
45 shell: bash
46 run: |
47 version=$(sed -n 's/^version = "\(.*\)"$/\1/p' Cargo.toml | head -n 1)
48 if [ "$GITHUB_REF_NAME" != "v$version" ]; then
49 echo "::error::tag $GITHUB_REF_NAME does not match version $version in Cargo.toml"
50 exit 1
51 fi
52
53 - uses: dtolnay/rust-toolchain@stable
54 with:
55 targets: ${{ matrix.target }}
56
57 - name: Install Linux GUI dependencies
58 if: runner.os == 'Linux'
59 run: |
60 sudo apt-get update
61 sudo apt-get install -y libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxkbcommon-dev libssl-dev
62
63 - uses: Swatinem/rust-cache@v2
64 with:
65 key: ${{ matrix.target }}
66
67 - name: Build
68 run: cargo build --release --locked --target ${{ matrix.target }} -p bench51-tui -p bench51-gui
69
70 - name: Package
71 shell: bash
72 run: |
73 name=bench51-${{ matrix.target }}
74 ext=
75 if [ "$RUNNER_OS" = Windows ]; then ext=.exe; fi
76 mkdir -p "dist/$name"
77 cp "target/${{ matrix.target }}/release/bench51$ext" "target/${{ matrix.target }}/release/bench51-gui$ext" "dist/$name/"
78 cp README.md LICENSE CHANGELOG.md "dist/$name/"
79 if [ "$RUNNER_OS" = Linux ]; then
80 mkdir -p "dist/$name/share/applications" "dist/$name/share/icons/hicolor/scalable/apps"
81 cp crates/bench51-gui/assets/bench51-gui.desktop "dist/$name/share/applications/"
82 cp crates/bench51-gui/assets/bench51-gui.svg "dist/$name/share/icons/hicolor/scalable/apps/"
83 fi
84 cd dist
85 if [ "$RUNNER_OS" = Windows ]; then
86 7z a -tzip "$name.zip" "$name" > /dev/null
87 else
88 tar -czf "$name.tar.gz" "$name"
89 fi
90 rm -rf "$name"
91 ls -l
92
93 - name: Install the archive and run it
94 if: runner.os != 'Windows' && !matrix.cross
95 shell: bash
96 run: |
97 sh install.sh --archive "dist/bench51-${{ matrix.target }}.tar.gz" --dir "$RUNNER_TEMP/bin" --no-desktop
98 "$RUNNER_TEMP/bin/bench51-gui" --version
99 printf 'ORG 0\nloop: MOV A,#1\n SJMP loop\n END\n' > "$RUNNER_TEMP/t.asm"
100 "$RUNNER_TEMP/bin/bench51" --assemble "$RUNNER_TEMP/t.asm"
101 test -s "$RUNNER_TEMP/t.hex"
102
103 - name: Install the archive and run it
104 if: runner.os == 'Windows'
105 shell: pwsh
106 run: |
107 ./install.ps1 -Archive "dist/bench51-${{ matrix.target }}.zip" -InstallDir "$env:RUNNER_TEMP\bench51" -NoShortcut
108 if ($LASTEXITCODE) { exit $LASTEXITCODE }
109 # The GUI has no console; check its exit code instead of its output.
110 $gui = Start-Process -FilePath "$env:RUNNER_TEMP\bench51\bench51-gui.exe" -ArgumentList '--version' -Wait -PassThru
111 if ($gui.ExitCode -ne 0) { exit 1 }
112
113 - uses: actions/upload-artifact@v7
114 with:
115 name: bench51-${{ matrix.target }}
116 path: dist/*
117 if-no-files-found: error
118
119 publish:
120 needs: build
121 if: startsWith(github.ref, 'refs/tags/v')
122 runs-on: ubuntu-latest
123 permissions:
124 contents: write
125 steps:
126 - uses: actions/checkout@v7
127
128 - uses: actions/download-artifact@v8
129 with:
130 path: dist
131 merge-multiple: true
132
133 - name: Checksums
134 run: |
135 cd dist
136 sha256sum -- * > SHA256SUMS
137 cat SHA256SUMS
138
139 - name: Release notes from CHANGELOG.md
140 run: |
141 version=${GITHUB_REF_NAME#v}
142 awk -v v="$version" '/^## \[/ { if (on) exit; on = index($0, "[" v "]") } on' CHANGELOG.md | tail -n +2 > notes.md
143 if [ ! -s notes.md ]; then
144 echo "::error::CHANGELOG.md has no section for $version"
145 exit 1
146 fi
147 cat notes.md
148
149 - name: Publish
150 env:
151 GH_TOKEN: ${{ github.token }}
152 run: gh release create "$GITHUB_REF_NAME" dist/* --verify-tag --title "bench51 $GITHUB_REF_NAME" --notes-file notes.md
153
154 # Installs the published release exactly as the README tells people to.
155 verify:
156 name: install on ${{ matrix.os }}
157 needs: publish
158 strategy:
159 fail-fast: false
160 matrix:
161 os: [ubuntu-latest, macos-latest, windows-latest]
162 runs-on: ${{ matrix.os }}
163 steps:
164 - name: One-line install
165 if: runner.os != 'Windows'
166 run: |
167 curl -fsSL "https://raw.githubusercontent.com/$GITHUB_REPOSITORY/$GITHUB_REF_NAME/install.sh" | sh
168 "$HOME/.local/bin/bench51" --version | grep -F "${GITHUB_REF_NAME#v}"
169 "$HOME/.local/bin/bench51-gui" --version | grep -F "${GITHUB_REF_NAME#v}"
170
171 - name: One-line install
172 if: runner.os == 'Windows'
173 shell: pwsh
174 run: |
175 irm "https://raw.githubusercontent.com/$env:GITHUB_REPOSITORY/$env:GITHUB_REF_NAME/install.ps1" | iex
176 $version = & "$env:LOCALAPPDATA\Programs\bench51\bench51.exe" --version
177 if ($version -notmatch [regex]::Escape($env:GITHUB_REF_NAME.TrimStart('v'))) { exit 1 }
178 if (-not (Test-Path "$([Environment]::GetFolderPath('Programs'))\bench51.lnk")) { exit 1 }