ci: container image improvements #117
This file contains 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
name: Release | |
on: | |
push: | |
branches: [ "release/**", "develop", "staging/**" ] | |
tags: [ "samedec-*" ] | |
permissions: | |
contents: write | |
env: | |
CARGO_TERM_COLOR: always | |
RUST_BACKTRACE: 1 | |
jobs: | |
# run `cargo vendor` and cache it | |
vendor_sources: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/cache@v4 | |
name: Update crate cargo-vendor cache | |
id: vendor_cache | |
with: | |
path: | | |
.cargo | |
vendor | |
key: cargo-vendor-release-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: | | |
cargo-vendor-release | |
cargo-vendor | |
enableCrossOsArchive: true | |
- uses: actions/cache@v4 | |
name: Update cargo registry cache | |
if: steps.vendor_cache.outputs.cache-hit != 'true' | |
with: | |
path: | | |
~/.cargo/bin/ | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
key: ${{ runner.os }}-cargo-cache-release-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: | | |
${{ runner.os }}-cargo-cache-release | |
${{ runner.os }}-cargo-cache | |
- name: Vendor sources | |
if: steps.vendor_cache.outputs.cache-hit != 'true' | |
run: | | |
mkdir -p .cargo | |
mkdir -p vendor | |
cargo vendor --versioned-dirs --locked >.cargo/config.toml | |
# Linux builds, with Docker and qemu as required | |
release_linux: | |
runs-on: ubuntu-latest | |
needs: vendor_sources | |
strategy: | |
matrix: | |
include: | |
- target: x86_64-unknown-linux-gnu | |
- target: aarch64-unknown-linux-gnu | |
- target: armv7-unknown-linux-gnueabihf | |
- target: i686-unknown-linux-gnu | |
container: | |
image: ghcr.io/cbs228/sameold/builder/${{ matrix.target }}:latest | |
credentials: | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
env: | |
CARGO_NET_OFFLINE: "true" | |
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse | |
RUSTFLAGS: '-C strip=symbols' | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/cache/restore@v4 | |
name: Restore crate cargo-vendor cache | |
with: | |
path: | | |
.cargo | |
vendor | |
key: cargo-vendor-release-${{ hashFiles('**/Cargo.lock') }} | |
enableCrossOsArchive: true | |
fail-on-cache-miss: true | |
- name: Cross-compile, cross-test, and install | |
run: | | |
cargo test --offline --frozen --release --workspace && | |
cargo install --offline --frozen --path=crates/samedec | |
- name: Run integration tests on release-mode build | |
run: | | |
qemu-run-maybe samedec --version && | |
cd sample && | |
./test.sh qemu-run-maybe samedec | |
- name: Copy artifact | |
run: | | |
cp /install/bin/samedec /install/bin/samedec-${{ matrix.target }} | |
- name: Store artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: samedec-${{ matrix.target }} | |
path: /install/bin/samedec-${{ matrix.target }} | |
retention-days: 3 | |
- name: Upload tagged release | |
uses: svenstaro/upload-release-action@v2 | |
if: startsWith(github.ref, 'refs/tags/samedec-') | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: /install/bin/samedec-${{ matrix.target }} | |
overwrite: true | |
- name: Update tag for nightly release | |
uses: richardsimko/update-tag@v1 | |
if: github.ref == 'refs/heads/develop' | |
with: | |
tag_name: latest | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload nightly release | |
uses: svenstaro/upload-release-action@v2 | |
if: github.ref == 'refs/heads/develop' | |
with: | |
tag: "latest" | |
release_name: "Nightly Release" | |
body: "This is a rolling release built from the latest `develop` branch." | |
prerelease: true | |
file: /install/bin/samedec-${{ matrix.target }} | |
overwrite: true | |
# Win32 build, on whatever machine github has available | |
release_windows: | |
runs-on: windows-latest | |
needs: vendor_sources | |
env: | |
CARGO_BUILD_TARGET: x86_64-pc-windows-msvc | |
CARGO_NET_OFFLINE: "true" | |
CARGO_INSTALL_ROOT: "install/" | |
RUSTFLAGS: '-C strip=symbols -C target-feature=+crt-static' | |
samedec_exe: 'install/bin/samedec.exe' | |
samedec_target_exe: install/bin/samedec-x86_64-pc-windows-msvc.exe | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Record environment | |
shell: bash | |
run: cargo version | |
- uses: actions/cache/restore@v4 | |
name: Restore crate cargo-vendor cache | |
with: | |
path: | | |
.cargo | |
vendor | |
key: cargo-vendor-release-${{ hashFiles('**/Cargo.lock') }} | |
enableCrossOsArchive: true | |
fail-on-cache-miss: true | |
- name: Build | |
shell: bash | |
run: | | |
mkdir -p 'install' && | |
cargo build --offline --tests --frozen --release --workspace | |
- name: Test and install | |
shell: bash | |
run: | | |
cargo test --offline --frozen --release --workspace && | |
cargo install --offline --frozen --path=crates/samedec | |
- name: Run integration tests | |
shell: bash | |
run: | | |
pushd sample && | |
./test.sh && | |
popd | |
- name: Copy artifact | |
shell: bash | |
run: | | |
cp "$samedec_exe" "$samedec_target_exe" | |
- name: Store artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: samedec-${{ env.CARGO_BUILD_TARGET }} | |
path: ${{ env.samedec_target_exe }} | |
retention-days: 3 | |
- name: Upload tagged release | |
uses: svenstaro/upload-release-action@v2 | |
if: startsWith(github.ref, 'refs/tags/samedec-') | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: ${{ env.samedec_target_exe }} | |
overwrite: true | |
- name: Upload nightly release | |
uses: svenstaro/upload-release-action@v2 | |
if: github.ref == 'refs/heads/develop' | |
with: | |
tag: "latest" | |
release_name: "Nightly Release" | |
body: "This is a rolling release built from the latest `develop` branch." | |
prerelease: true | |
file: ${{ env.samedec_target_exe }} | |
overwrite: true | |
# MacOS build, on whatever machine github has available | |
release_macos: | |
runs-on: macos-latest | |
needs: vendor_sources | |
env: | |
CARGO_BUILD_TARGET: aarch64-apple-darwin | |
CARGO_NET_OFFLINE: "true" | |
CARGO_INSTALL_ROOT: "install/" | |
RUSTFLAGS: '-C strip=symbols' | |
samedec_exe: 'install/bin/samedec' | |
samedec_target_exe: install/bin/samedec-aarch64-apple-darwin | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Record environment | |
run: cargo version | |
- uses: actions/cache/restore@v4 | |
name: Restore crate cargo-vendor cache | |
with: | |
path: | | |
.cargo | |
vendor | |
key: cargo-vendor-release-${{ hashFiles('**/Cargo.lock') }} | |
enableCrossOsArchive: true | |
fail-on-cache-miss: true | |
- name: Build | |
run: | | |
mkdir -p 'install' && | |
cargo fetch --locked && | |
cargo build --offline --tests --frozen --release --workspace | |
- name: Test and install | |
run: | | |
cargo test --offline --frozen --release --workspace && | |
cargo install --offline --frozen --path=crates/samedec | |
- name: Run integration tests | |
run: | | |
pushd sample && | |
./test.sh && | |
popd | |
- name: Copy artifact | |
run: | | |
cp "$samedec_exe" "$samedec_target_exe" | |
- name: Store artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: samedec-${{ env.CARGO_BUILD_TARGET }} | |
path: ${{ env.samedec_target_exe }} | |
retention-days: 3 | |
- name: Upload tagged release | |
uses: svenstaro/upload-release-action@v2 | |
if: startsWith(github.ref, 'refs/tags/samedec-') | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: ${{ env.samedec_target_exe }} | |
overwrite: true | |
- name: Upload nightly release | |
uses: svenstaro/upload-release-action@v2 | |
if: github.ref == 'refs/heads/develop' | |
with: | |
tag: "latest" | |
release_name: "Nightly Release" | |
body: "This is a rolling release built from the latest `develop` branch." | |
prerelease: true | |
file: ${{ env.samedec_target_exe }} | |
overwrite: true |