Repository navigation
fix: pack from the dispatch commit and upload only missing assets #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,179 +1,212 @@ | ||
| name: Release assets | ||
|
|
||
| on: | ||
| pull_request: | ||
| workflow_dispatch: | ||
| inputs: | ||
| publish: | ||
| description: Upload archives to an existing GitHub Release | ||
| type: boolean | ||
| default: false | ||
| tag: | ||
| description: Existing tag, for example v0.7.0 | ||
| required: false | ||
| type: string | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: release-assets-${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| package: | ||
| name: Package (${{ matrix.target_os }}/${{ matrix.arch }}) | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - os: windows-latest | ||
| target_os: windows | ||
| arch: x86_64 | ||
| binary: rob.exe | ||
| - os: ubuntu-latest | ||
| target_os: linux | ||
| arch: x86_64 | ||
| binary: rob | ||
| - os: macos-15 | ||
| target_os: macos | ||
| arch: aarch64 | ||
| binary: rob | ||
| # Standard (free) runner on public repos; no -large suffix needed. | ||
| # Emits macos-x86_64 so Rokit can serve Intel Macs, which it otherwise | ||
| # cannot detect: Rokit validates OS but not architecture. | ||
| - os: macos-15-intel | ||
| target_os: macos | ||
| arch: x86_64 | ||
| binary: rob | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.event_name == 'workflow_dispatch' && inputs.publish && inputs.tag || github.sha }} | ||
| persist-credentials: false | ||
|
|
||
| - name: Record the built commit | ||
| shell: bash | ||
| env: | ||
| RELEASE_TAG: ${{ inputs.tag }} | ||
| REQUIRE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.publish }} | ||
| run: | | ||
| set -euo pipefail | ||
| sha="$(git rev-parse HEAD)" | ||
| printf '%s\n' "$sha" > built-commit.txt | ||
| if [[ "$REQUIRE_TAG" == "true" ]]; then | ||
| if [[ ! "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
| echo "tag is not a plain version" >&2 | ||
| exit 1 | ||
| fi | ||
| test "$sha" = "$(git rev-parse "${RELEASE_TAG}^{commit}")" | ||
| fi | ||
|
|
||
| - uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| toolchain: 1.99.0 | ||
|
|
||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.12" | ||
|
|
||
| - name: Build | ||
| run: cargo build --release --locked | ||
|
|
||
| - name: Offline smoke | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| bin="target/release/${{ matrix.binary }}" | ||
| "$bin" --version | ||
| "$bin" schema >/dev/null | ||
| "$bin" users link --user 1 >/dev/null | ||
|
|
||
| - name: Pack | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1)" | ||
| python scripts/package-release.py \ | ||
| --version "$version" \ | ||
| --os "${{ matrix.target_os }}" \ | ||
| --arch "${{ matrix.arch }}" \ | ||
| --binary "target/release/${{ matrix.binary }}" \ | ||
| --licenses . \ | ||
| --out dist | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: robcli-${{ matrix.target_os }}-${{ matrix.arch }} | ||
| path: dist/* | ||
| if-no-files-found: error | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: built-commit-${{ matrix.target_os }}-${{ matrix.arch }} | ||
| path: built-commit.txt | ||
| if-no-files-found: error | ||
|
|
||
| publish: | ||
| name: Upload existing release | ||
| if: github.event_name == 'workflow_dispatch' && inputs.publish | ||
| needs: package | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ inputs.tag }} | ||
| persist-credentials: false | ||
|
|
||
| - name: Require the built commit to still be the tag | ||
| shell: bash | ||
| env: | ||
| RELEASE_TAG: ${{ inputs.tag }} | ||
| run: | | ||
| set -euo pipefail | ||
| if [[ ! "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
| echo "tag is not a plain version" >&2 | ||
| exit 1 | ||
| fi | ||
| version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1)" | ||
| test "$RELEASE_TAG" = "v${version}" | ||
| expected="$(git rev-parse "${RELEASE_TAG}^{commit}")" | ||
| test "$expected" = "$(git rev-parse HEAD)" | ||
|
|
||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| pattern: robcli-* | ||
| path: dist | ||
| merge-multiple: true | ||
|
|
||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| pattern: built-commit-* | ||
| path: commits | ||
|
|
||
| - name: Reject archives built from another commit | ||
| shell: bash | ||
| env: | ||
| RELEASE_TAG: ${{ inputs.tag }} | ||
| run: | | ||
| set -euo pipefail | ||
| expected="$(git rev-parse "${RELEASE_TAG}^{commit}")" | ||
| found=0 | ||
| while IFS= read -r file; do | ||
| found=$((found + 1)) | ||
| test "$(tr -d '\r\n' < "$file")" = "$expected" | ||
| done < <(find commits -name built-commit.txt | sort) | ||
| test "$found" -eq 4 | ||
|
|
||
| - name: Upload without replacing assets | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| RELEASE_TAG: ${{ inputs.tag }} | ||
| REPOSITORY: ${{ github.repository }} | ||
| run: | | ||
| set -euo pipefail | ||
| gh release view "$RELEASE_TAG" --repo "$REPOSITORY" | ||
| gh release upload "$RELEASE_TAG" dist/* --repo "$REPOSITORY" | ||
| name: Release assets | ||
|
|
||
| on: | ||
| pull_request: | ||
| workflow_dispatch: | ||
| inputs: | ||
| publish: | ||
| description: Upload archives to an existing GitHub Release | ||
| type: boolean | ||
| default: false | ||
| tag: | ||
| description: Existing tag, for example v0.7.0 | ||
| required: false | ||
| type: string | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: release-assets-${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| package: | ||
| name: Package (${{ matrix.target_os }}/${{ matrix.arch }}) | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - os: windows-latest | ||
| target_os: windows | ||
| arch: x86_64 | ||
| binary: rob.exe | ||
| - os: ubuntu-latest | ||
| target_os: linux | ||
| arch: x86_64 | ||
| binary: rob | ||
| - os: macos-15 | ||
| target_os: macos | ||
| arch: aarch64 | ||
| binary: rob | ||
| # Standard (free) runner on public repos; no -large suffix needed. | ||
| # Emits macos-x86_64 so Rokit can serve Intel Macs, which it otherwise | ||
| # cannot detect: Rokit validates OS but not architecture. | ||
| - os: macos-15-intel | ||
| target_os: macos | ||
| arch: x86_64 | ||
| binary: rob | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.event_name == 'workflow_dispatch' && inputs.publish && inputs.tag || github.sha }} | ||
| persist-credentials: false | ||
|
|
||
| # A tag that predates this workflow has no scripts/package-release.py in | ||
| # its tree, so the packer is taken from the dispatch commit instead. This | ||
| # is what makes backfilling assets onto an older release possible. | ||
| - name: Check out packaging tooling | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.sha }} | ||
| path: tooling | ||
| persist-credentials: false | ||
|
|
||
| - name: Record the built commit | ||
| shell: bash | ||
| env: | ||
| RELEASE_TAG: ${{ inputs.tag }} | ||
| REQUIRE_TAG: ${{ github.event_name == 'workflow_dispatch' && inputs.publish }} | ||
| run: | | ||
| set -euo pipefail | ||
| sha="$(git rev-parse HEAD)" | ||
| printf '%s\n' "$sha" > built-commit.txt | ||
| if [[ "$REQUIRE_TAG" == "true" ]]; then | ||
| if [[ ! "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
| echo "tag is not a plain version" >&2 | ||
| exit 1 | ||
| fi | ||
| test "$sha" = "$(git rev-parse "${RELEASE_TAG}^{commit}")" | ||
| fi | ||
|
|
||
| - uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| toolchain: 1.99.0 | ||
|
|
||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.12" | ||
|
|
||
| - name: Build | ||
| run: cargo build --release --locked | ||
|
|
||
| - name: Offline smoke | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| bin="target/release/${{ matrix.binary }}" | ||
| "$bin" --version | ||
| "$bin" schema >/dev/null | ||
| "$bin" users link --user 1 >/dev/null | ||
|
|
||
| - name: Pack | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1)" | ||
| python tooling/scripts/package-release.py \ | ||
| --version "$version" \ | ||
| --os "${{ matrix.target_os }}" \ | ||
| --arch "${{ matrix.arch }}" \ | ||
| --binary "target/release/${{ matrix.binary }}" \ | ||
| --licenses . \ | ||
| --out dist | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: robcli-${{ matrix.target_os }}-${{ matrix.arch }} | ||
| path: dist/* | ||
| if-no-files-found: error | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: built-commit-${{ matrix.target_os }}-${{ matrix.arch }} | ||
| path: built-commit.txt | ||
| if-no-files-found: error | ||
|
|
||
| publish: | ||
| name: Upload existing release | ||
| if: github.event_name == 'workflow_dispatch' && inputs.publish | ||
| needs: package | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ inputs.tag }} | ||
| persist-credentials: false | ||
|
|
||
| - name: Require the built commit to still be the tag | ||
| shell: bash | ||
| env: | ||
| RELEASE_TAG: ${{ inputs.tag }} | ||
| run: | | ||
| set -euo pipefail | ||
| if [[ ! "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
| echo "tag is not a plain version" >&2 | ||
| exit 1 | ||
| fi | ||
| version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1)" | ||
| test "$RELEASE_TAG" = "v${version}" | ||
| expected="$(git rev-parse "${RELEASE_TAG}^{commit}")" | ||
| test "$expected" = "$(git rev-parse HEAD)" | ||
|
|
||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| pattern: robcli-* | ||
| path: dist | ||
| merge-multiple: true | ||
|
|
||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| pattern: built-commit-* | ||
| path: commits | ||
|
|
||
| - name: Reject archives built from another commit | ||
| shell: bash | ||
| env: | ||
| RELEASE_TAG: ${{ inputs.tag }} | ||
| run: | | ||
| set -euo pipefail | ||
| expected="$(git rev-parse "${RELEASE_TAG}^{commit}")" | ||
| found=0 | ||
| while IFS= read -r file; do | ||
| found=$((found + 1)) | ||
| test "$(tr -d '\r\n' < "$file")" = "$expected" | ||
| done < <(find commits -name built-commit.txt | sort) | ||
| test "$found" -eq 4 | ||
|
|
||
| - name: Upload without replacing assets | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| RELEASE_TAG: ${{ inputs.tag }} | ||
| REPOSITORY: ${{ github.repository }} | ||
| run: | | ||
| set -euo pipefail | ||
| gh release view "$RELEASE_TAG" --repo "$REPOSITORY" | ||
|
|
||
| # Upload only assets the release does not already have. A backfill | ||
| # exists precisely to add one new archive to a release that already | ||
| # holds the others, and `gh release upload` refuses the whole batch | ||
| # when any single name already exists. | ||
| existing="$(gh release view "$RELEASE_TAG" --repo "$REPOSITORY" --json assets --jq '.assets[].name')" | ||
|
|
||
| to_upload=() | ||
| for file in dist/*; do | ||
| name="$(basename "$file")" | ||
| if grep -Fxq "$name" <<< "$existing"; then | ||
| echo "already present, skipping: $name" | ||
| else | ||
| echo "uploading: $name" | ||
| to_upload+=("$file") | ||
| fi | ||
| done | ||
|
|
||
| if [ "${#to_upload[@]}" -eq 0 ]; then | ||
| echo "nothing to upload; the release already has every asset" | ||
| exit 0 | ||
| fi | ||
|
|
||
| gh release upload "$RELEASE_TAG" "${to_upload[@]}" --repo "$REPOSITORY" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: eiei114/robcli
Length of output: 1827
Refuse partial archive and checksum pairs instead of uploading the missing member.
The packer does not produce byte-stable archives. A release can hold one member of an archive/checksum pair. In that state, the filter uploads a checksum for newly built bytes beside a published archive with different bytes, so the published
.sha256fails verification. Because the rebuilt bytes can differ, the comment's byte comparison cannot find a match. Refuse the partial pair instead.🐛 Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents