name: ci
on:
push:
branches:
- main
- dev
- major
- minor
- patch
- prerelease
jobs:
pre:
name: Preprocessing
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
version: ${{ steps.version.outputs.version }}
increment: ${{ steps.increment.outputs.increment }}
steps:
- uses: actions/checkout@v3
- run: git fetch --tags origin
- run: |
if [[ ${{ github.ref_name }} == 'main' ]]; then
echo "increment=patch" >> $GITHUB_OUTPUT
elif [[ ${{ github.ref_name }} == 'dev' ]]; then
echo "increment=prerelease" >> $GITHUB_OUTPUT
else
echo "increment=${{ github.ref_name }}" >> $GITHUB_OUTPUT
fi
id: increment
- run: echo "matrix=$(jq -rc . .github/workflows/matrix.json)" >> $GITHUB_OUTPUT
id: matrix
- run: echo "version=$(ARG=next-${{ steps.increment.outputs.increment }}-version make py)" >> $GITHUB_OUTPUT
id: version
- name: DEBUG
run: echo ${{ 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
- run: make ci-git-user
- name: Run tests
run: make ci-test
crates-io-publish:
name: Publish to Crates.io
needs: [pre, build-and-test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get git tags
run: git fetch --tags origin
- run: make ci-git-user
- name: Increment prerelease version number
run: make py
env:
ARG: increment-${{ needs.pre.outputs.increment }}
- uses: katyo/publish-crates@v2
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
release:
name: Release on GitHub
needs: [pre, build-and-test, crates-io-publish]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.pre.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
- 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: make ci-build
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.pre.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
with:
tag_name: v${{ needs.pre.outputs.version }}
files: ${{ env.ASSET }}