Skip to content

Commit

Permalink
Automatically release a binary (and dotslash file) (#42)
Browse files Browse the repository at this point in the history
Summary:
This makes it much easier to use this repo from GitHub projects.

Pull Request resolved: #42

Test Plan:
Manually run action on my fork: https://github.com/bigfootjon/reindeer/actions/runs/8175293540

Which generates a release: https://github.com/bigfootjon/reindeer/releases

Downloading the dotslash file from that repo and running it works:

```
jonjanzen@jonjanzen-mbp Downloads % dotslash.oss reindeer --help
Usage: reindeer [OPTIONS] <COMMAND>

Commands:
  update    Update Cargo.lock with new dependencies
  vendor    Vendor crate needed for build
  buckify   Generate Buck build rules for Cargo packages
  auditsec  Show security report for vendored crates
  help      Print this message or the help of the given subcommand(s)

Options:
      --cargo-path <PATH>         Path to `cargo` command
      --rustc-path <PATH>         Path to `rustc` command
      --cargo-options <ARGUMENT>  Extra cargo options
      --third-party-dir <PATH>    Path to third-party dir [default: .]
  -h, --help                      Print help
```

Reviewed By: shayne-fletcher

Differential Revision: D54561053

Pulled By: bigfootjon

fbshipit-source-id: 6ce623ccd57f93ebdee62700eafe694a2fabb199
  • Loading branch information
bigfootjon authored and facebook-github-bot committed Mar 6, 2024
1 parent aa28922 commit 3ec771e
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/dotslash-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"exclude-github-release-provider": true,
"outputs": {
"reindeer": {
"platforms": {
"macos-aarch64": {
"regex": "^reindeer-aarch64-apple-darwin.zst$",
"path": "reindeer-aarch64-apple-darwin"
},
"linux-aarch64": {
"regex": "^reindeer-aarch64-unknown-linux-musl.zst$",
"path": "reindeer-aarch64-unknown-linux-musl"
},
"macos-x86_64": {
"regex": "^reindeer-x86_64-apple-darwin.zst$",
"path": "reindeer-x86_64-apple-darwin"
},
"windows-x86_64": {
"regex": "^reindeer-x86_64-pc-windows-msvc.exe.zst$",
"path": "reindeer-x86_64-pc-windows-msvc.exe"
},
"linux-x86_64": {
"regex": "^reindeer-x86_64-unknown-linux-musl.zst$",
"path": "reindeer-x86_64-unknown-linux-musl"
}
}
}
}
}
125 changes: 125 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
on:
push:
tags:
# Only match TagIt tags, which always start with this prefix
- 'v20*'
workflow_dispatch:

name: Publish Release

jobs:
build:
strategy:
fail-fast: false
matrix:
target:
- os: 'ubuntu-22.04'
triple: 'aarch64-unknown-linux-gnu'
cross: true
- os: 'ubuntu-22.04'
triple: 'aarch64-unknown-linux-musl'
cross: true
- os: 'ubuntu-22.04'
triple: 'x86_64-unknown-linux-gnu'
- os: 'ubuntu-22.04'
triple: 'x86_64-unknown-linux-musl'
cross: true
- os: 'macos-14'
triple: 'aarch64-apple-darwin'
- os: 'macos-12'
triple: 'x86_64-apple-darwin'
- os: 'windows-2022'
triple: 'x86_64-pc-windows-msvc'
is_windows: true
runs-on: ${{ matrix.target.os }}

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
# This makes sure that this executable is portable:
- name: Vendor openssl
run: cargo add openssl-sys -F vendored
if: ${{ !matrix.target.is_windows }}
- uses: SebRollen/[email protected]
id: read_rust_toolchain
with:
file: 'rust-toolchain'
field: 'toolchain.channel'
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: ${{ steps.read_rust_toolchain.outputs.value }}
targets: ${{ matrix.target.triple }}
- uses: Swatinem/rust-cache@v2
with:
prefix-key: reindeer-upload
key: ${{ matrix.target.triple }}
- uses: actions-rs/[email protected]
if: matrix.target.cross
with:
crate: cross
version: latest
- name: Set variables
id: set_variables
shell: bash
run: |
if [ -n "${{ matrix.target.is_windows }}" ]; then
echo "cargo_out=target/${{ matrix.target.triple }}/release/reindeer.exe" >> "$GITHUB_OUTPUT"
echo "reindeer_zst=artifacts/reindeer-${{ matrix.target.triple }}.exe.zst" >> "$GITHUB_OUTPUT"
else
echo "cargo_out=target/${{ matrix.target.triple }}/release/reindeer" >> "$GITHUB_OUTPUT"
echo "reindeer_zst=artifacts/reindeer-${{ matrix.target.triple }}.zst" >> "$GITHUB_OUTPUT"
fi
- name: Build
shell: bash
env:
RUSTFLAGS: "-C strip=debuginfo -C codegen-units=1"
run: |
if [ -n "${{ matrix.target.cross }}" ]; then
CARGO=cross
else
CARGO=cargo
fi
$CARGO build --locked --release --bin reindeer --target ${{ matrix.target.triple }}
- name: Move binary to artifacts/
shell: bash
run: |
mkdir artifacts
zstd -z ${{ steps.set_variables.outputs.cargo_out }} -o ${{ steps.set_variables.outputs.reindeer_zst }}
- name: Upload
uses: actions/upload-artifact@v3
with:
name: reindeer-${{ matrix.target.triple }}
path: ${{ steps.set_variables.outputs.reindeer_zst }}

release:
needs:
- build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- shell: bash
run: |
mkdir -p ${{github.workspace}}/artifacts
- uses: actions/download-artifact@v3
with:
path: ${{github.workspace}}/artifacts
- name: Display structure of downloaded files
shell: bash
run: |
ls -R artifacts
- uses: pyTooling/Actions/releaser@adef08d3bdef092282614f3b683897cefae82ee3 # v0.4.6
id: upload_attempt_1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: '${{ github.ref_name }}'
files: ${{ github.workspace }}/artifacts/**
rm: false # do not clean past assets
- uses: facebook/dotslash-publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
config: .github/dotslash-config.json
tag: '${{ github.ref_name }}'

0 comments on commit 3ec771e

Please sign in to comment.