Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenvukhang committed Jul 6, 2023
2 parents 4476cb2 + 6fe0071 commit a5c0a43
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 374 deletions.
79 changes: 45 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
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
Expand All @@ -24,9 +23,9 @@ jobs:
# Sets the increment: how much to push the version number
- run: |
case ${{ github.ref_name }} in
main) echo "increment=release" >> $GITHUB_OUTPUT;;
dev) echo "increment=patch-pre" >> $GITHUB_OUTPUT;;
*) echo "increment=${{ github.ref_name }}-pre" >> $GITHUB_OUTPUT;;
main) echo "increment=patch" >> $GITHUB_OUTPUT ;;
dev) echo "increment=prerelease" >> $GITHUB_OUTPUT ;;
*) echo "increment=${{ github.ref_name }}" >> $GITHUB_OUTPUT;;
esac
id: increment
Expand All @@ -35,16 +34,10 @@ jobs:
- run: echo "matrix=$(jq -rc . .github/workflows/matrix.json)" >> $GITHUB_OUTPUT
id: matrix

# Checks that the version on Cargo.toml matches the latest git
# tag, and sets the `version` variable to the next version.
- run: echo "version=$(ARG=next-${{ steps.increment.outputs.increment }} make py)" >> $GITHUB_OUTPUT
id: version

- name: Enumerate outputs
run: |
echo ${{ steps.increment.outputs.increment }}
echo ${{ steps.version.outputs.version }}
echo ${{ steps.matrix.outputs.matrix }}
echo 'increment: ${{ steps.increment.outputs.increment }}'
echo 'matrix: ${{ steps.version.outputs.version }}'
build-and-test:
name: Build & Test
Expand All @@ -56,45 +49,63 @@ jobs:

steps:
- uses: actions/checkout@v3

# required for tests
- run: make ci-git-user

- name: Run tests
run: make test
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
increment:
name: Increment ${{ needs.pre.outputs.increment }} version
inc:
name: Increment version
needs: [pre, build-and-test]
runs-on: ubuntu-latest
outputs:
version: ${{ steps.semver.outputs.version }}
steps:
- uses: actions/checkout@v3
- run: git fetch --tags
- run: make ci-git-user
- uses: nguyenvukhang/semver-increment@v1
id: semver
with:
increment: ${{ needs.pre.outputs.increment }}
identifier: "alpha"
version-file: "Cargo.toml"
version-regex: '^version = "(.*)"'

- name: Increment ${{ needs.pre.outputs.increment }} version
run: make py
env:
ARG: increment-${{ needs.pre.outputs.increment }}
- 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 == 'release'
needs: [pre, increment]
if: needs.pre.outputs.increment != 'prerelease'
needs: [pre, inc]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: v${{ needs.pre.outputs.version }}
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, increment]
needs: [pre, inc]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -103,15 +114,15 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.pre.outputs.increment == 'release' && format('v{0}', needs.pre.outputs.version) || github.ref }}
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: make build
run: cargo build --release
env:
CARGO_BUILD_TARGET_DIR: ${{ env.TARGET_DIR }}

Expand All @@ -122,15 +133,15 @@ jobs:

- name: Build archive
run: |
STAGING="git-nu-v${{ needs.pre.outputs.version }}-${{ matrix.target }}"
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 == 'release' }}
if: ${{ needs.pre.outputs.increment != 'prerelease' }}
with:
tag_name: v${{ needs.pre.outputs.version }}
tag_name: v${{ needs.inc.outputs.version }}
files: ${{ env.ASSET }}
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gitnu"
version = "0.7.1"
version = "0.7.2-alpha.1"
authors = ["Nguyen Vu Khang <[email protected]>"]
description = """
gitnu indexes your git status so you can use numbers instead of filenames.
Expand Down
22 changes: 3 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ LOCAL_BIN=$(HOME)/dots/personal/.local/bin
GITNU_RELEASE_BIN=$(PWD)/target/release/git-nu
GITNU_DEBUG_BIN=$(PWD)/target/debug/git-nu

PY_UTILS := python3 scripts/utils.py
ONE_TEST := 'tests::renames'

current:
Expand All @@ -13,36 +12,21 @@ install:
make build
make load-bin

dev:
cargo build
cargo test --lib

build:
cargo build --bin git-nu --release
@echo "Release build complete."

test:
cargo build
GITNU_DEBUG=0 cargo test --lib
cargo test --lib

test-one:
cargo build
GITNU_DEBUG=0 cargo test $(ONE_TEST)
cargo test $(ONE_TEST)

# copies built binary to a path specified by $BIN
load-bin:
@rm -f $(LOCAL_BIN)/git-nu
@cp $(GITNU_RELEASE_BIN) $(LOCAL_BIN)


# ────────────────────────────────────────────────────────────────────
# MARK: - CI

ci-git-user:
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'

py:
@$(PY_UTILS) $(ARG)

.PHONY: test load-bin
.PHONY: test test-one load-bin
13 changes: 0 additions & 13 deletions scripts/get-git-commands.py

This file was deleted.

Loading

0 comments on commit a5c0a43

Please sign in to comment.