Merge branch 'dev' #453
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: | |
push: | |
branches: | |
- main | |
- dev | |
- major | |
- minor | |
- patch | |
jobs: | |
pre: | |
name: Preprocessing | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.matrix.outputs.matrix }} | |
increment: ${{ steps.increment.outputs.increment }} | |
steps: | |
- uses: actions/checkout@v3 | |
- run: git fetch --tags | |
# Sets the increment: how much to push the version number | |
- run: | | |
case ${{ github.ref_name }} in | |
main) echo "increment=patch" >> $GITHUB_OUTPUT ;; | |
dev) echo "increment=prerelease" >> $GITHUB_OUTPUT ;; | |
*) echo "increment=${{ github.ref_name }}" >> $GITHUB_OUTPUT;; | |
esac | |
id: increment | |
# Obtains the matrix strategy from `./matrix.json` to use for | |
# building, testing, and releasing artifacts on GitHub Releases | |
- run: echo "matrix=$(jq -rc . .github/workflows/matrix.json)" >> $GITHUB_OUTPUT | |
id: matrix | |
- name: Enumerate outputs | |
run: | | |
echo 'increment: ${{ steps.increment.outputs.increment }}' | |
echo 'matrix: ${{ steps.version.outputs.version }}' | |
build-and-test: | |
name: Build & Test | |
needs: [pre] | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJson(needs.pre.outputs.matrix) }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Run tests | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
cargo build | |
cargo test --lib | |
inc: | |
name: Increment version | |
needs: [pre, build-and-test] | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.semver.outputs.version }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: nguyenvukhang/semver-increment@v1 | |
id: semver | |
with: | |
increment: ${{ needs.pre.outputs.increment }} | |
identifier: "alpha" | |
version-file: "Cargo.toml" | |
version-regex: '^version = "(.*)"' | |
- name: Commit and push | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
cargo build | |
git add Cargo.toml Cargo.lock | |
git commit -m 'ver: bump to ${{ steps.semver.outputs.version }}' | |
git push | |
- name: Tag and push | |
if: ${{ needs.pre.outputs.increment != 'prerelease' }} | |
run: | | |
git tag v${{ steps.semver.outputs.version }} | |
git push --tag | |
# publish patch-level updates and above only | |
publish-crates-io: | |
name: Publish to Crates.io | |
if: needs.pre.outputs.increment != 'prerelease' | |
needs: [pre, inc] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: v${{ needs.inc.outputs.version }} | |
- uses: katyo/publish-crates@v2 | |
with: | |
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
release-github: | |
name: Release on GitHub | |
needs: [pre, inc] | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJson(needs.pre.outputs.matrix) }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ needs.pre.outputs.increment != 'prerelease' && format('v{0}', needs.inc.outputs.version) || github.ref }} | |
- run: | | |
TARGET_DIR=./target/${{ matrix.target }} | |
echo "TARGET_DIR=$TARGET_DIR" >> $GITHUB_ENV | |
echo "BINFILE=$TARGET_DIR/release/git-nu" >> $GITHUB_ENV | |
- name: Build binary | |
run: cargo build --release | |
env: | |
CARGO_BUILD_TARGET_DIR: ${{ env.TARGET_DIR }} | |
- name: Strip release binary | |
if: >- | |
(matrix.build == 'linux' || matrix.build == 'linux-arm' || matrix.build == 'macos') | |
run: strip ${{ env.BINFILE }} | |
- name: Build archive | |
run: | | |
STAGING="git-nu-v${{ needs.inc.outputs.version }}-${{ matrix.target }}" | |
mkdir -p "$STAGING" | |
cp ${{ env.BINFILE }} "$STAGING" | |
tar czf "$STAGING.tar.gz" "$STAGING" | |
echo "ASSET=$STAGING.tar.gz" >> $GITHUB_ENV | |
- name: Release | |
uses: softprops/action-gh-release@v1 | |
if: ${{ needs.pre.outputs.increment != 'prerelease' }} | |
with: | |
tag_name: v${{ needs.inc.outputs.version }} | |
files: ${{ env.ASSET }} |