ci #1745
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: ci | |
on: | |
pull_request: | |
push: | |
branches: ['master'] | |
tags: ['v*'] | |
schedule: | |
- cron: '00 01 * * *' | |
jobs: | |
test: | |
name: test | |
runs-on: ${{ matrix.os }} | |
env: | |
CARGO: cargo | |
TARGET: | |
strategy: | |
fail-fast: false | |
matrix: | |
build: | |
- x86_64-unknown-linux-musl | |
- x86_64-apple-darwin | |
- aarch64-apple-darwin | |
- x86_64-pc-windows-msvc | |
include: | |
- build: x86_64-unknown-linux-musl | |
os: ubuntu-latest | |
- build: x86_64-apple-darwin | |
os: macos-13 | |
- build: aarch64-apple-darwin | |
os: macos-14 | |
- build: x86_64-pc-windows-msvc | |
os: windows-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Cross | |
if: matrix.os == 'ubuntu-latest' | |
run: | | |
cargo install cross | |
echo "CARGO=cross" >> $GITHUB_ENV | |
- name: Build | |
run: ${{ env.CARGO }} build --verbose --target "${{ matrix.build }}" | |
- name: Tests | |
run: ${{ env.CARGO }} test --verbose --target "${{ matrix.build }}" | |
- name: Build Release | |
run: ${{ env.CARGO }} build --release --verbose --target "${{ matrix.build }}" | |
- name: Stage Release | |
shell: bash | |
run: | | |
if [[ "${GITHUB_REF}" = *refs/tags/* ]]; then | |
VERSION="${GITHUB_REF#refs/tags/}" | |
else | |
VERSION="vnightly" | |
fi | |
echo "version is $VERSION" | |
STAGING="rrrocket-${VERSION:1}-${{ matrix.build }}" | |
echo "STAGING DIR: $STAGING" | |
mkdir $STAGING | |
if [[ "${{ matrix.os }}" = windows* ]]; then | |
cp "target/${{ matrix.build }}/release/rrrocket.exe" "$STAGING/" | |
else | |
cp "target/${{ matrix.build }}/release/rrrocket" "$STAGING/" | |
fi | |
echo "ASSET=$STAGING" >> $GITHUB_ENV | |
- uses: actions/upload-artifact@v4 | |
with: | |
path: ${{ env.ASSET }} | |
name: ${{ env.ASSET }} | |
if-no-files-found: error | |
release: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
path: artifacts-temp | |
- name: Flatten artifacts | |
run: | | |
mkdir artifacts | |
cd artifacts-temp | |
for i in *; do | |
if [[ "$i" = *windows* ]]; then | |
7z a "../artifacts/$(basename "$i").zip" "$i" | |
else | |
tar czf "../artifacts/$(basename "$i").tar.gz" "$i" | |
fi | |
done | |
ls -lR ../artifacts | |
- name: Create Release | |
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
console.log('environment', process.versions); | |
const fs = require('fs').promises; | |
const { repo: { owner, repo }, sha } = context; | |
console.log({ owner, repo, sha }); | |
const tag_name = process.env.GITHUB_REF.split("/")[2]; | |
const release = await github.rest.repos.createRelease({ | |
owner, repo, | |
tag_name, | |
draft: false, | |
target_commitish: sha | |
}); | |
console.log('created release', { release }); | |
for (let file of await fs.readdir('artifacts')) { | |
console.log('uploading', file); | |
await github.rest.repos.uploadReleaseAsset({ | |
owner, repo, | |
release_id: release.data.id, | |
name: file, | |
data: await fs.readFile(`artifacts/${file}`) | |
}); | |
} |