Skip to content

Commit

Permalink
ci: Add pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
tomphp committed Oct 23, 2023
1 parent fe41245 commit 4b5e023
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 4 deletions.
131 changes: 131 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: Pipeline
on:
push:
branches:
- '*'
pull_request:

permissions:
contents: write

jobs:
run-tests:
uses: ./.github/workflows/run-tests.yml

bump-cargo-version:
runs-on: ubuntu-latest
needs:
- run-tests
if: github.ref == 'refs/heads/main' && needs.run-tests.outputs.will-bump == 'true'
steps:
- uses: actions/checkout@v4
name: Checkout the repository
- uses: actions/[email protected]
name: Cache cargo dependencies
with:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
path: |
.cache
~/.cargo/registry
~/.cargo/git
~/.cargo/bin
target
- uses: actions-rs/[email protected]
name: Install rust toolchain
with:
default: true
profile: minimal
toolchain: stable
- uses: actions-rs/[email protected]
name: Build release version
with:
args: --release --locked
command: build
- name: Install cargo-edit
run: cargo install cargo-edit
- name: Set Cargo version
run: cargo set-version "${NEW_VERSION#v}"
env:
NEW_VERSION: ${{ needs.run-tests.outputs.bump-version }}
- name: Store updated Cargo files
uses: actions/upload-artifact@v3
with:
name: bumped-files
path: Cargo.*

build-binaries:
if: github.ref == 'refs/heads/main'
runs-on: ${{ matrix.os }}
needs:
- run-tests
steps:
- run: ${{ matrix.install }}
env:
DEBIAN_FRONTEND: noninteractive
name: Install additional dependencies
- uses: actions/checkout@v4
name: Checkout the repository
- uses: actions/[email protected]
name: Cache cargo dependencies
with:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
path: |
.cache
~/.cargo/registry
~/.cargo/git
~/.cargo/bin
target
- uses: actions-rs/[email protected]
name: Install rust toolchain
with:
default: true
profile: minimal
toolchain: stable
- uses: actions-rs/[email protected]
name: Build release version
with:
args: --release --locked
command: build
- id: get_repository_name
name: Calculate repository name
run: echo "REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk
-F / '{print $2}' | sed -e "s/:refs//")" >> "$GITHUB_OUTPUT"
shell: bash
- name: Move binary to upload location
env:
TARGET: ${{ matrix.target }}
EXTENSION: ${{ matrix.suffix }}
REPOSITORY_NAME: ${{ steps.get_repository_name.outputs.REPOSITORY_NAME }}
run: mv "./target/release/$REPOSITORY_NAME$EXTENSION" "./$REPOSITORY_NAME-$TARGET$EXTENSION"
shell: bash
- uses: actions/upload-artifact@v3
name: Store built binary version
with:
name: bins
path: ${{ steps.get_repository_name.outputs.REPOSITORY_NAME }}-${{ matrix.target }}${{ matrix.suffix }}
strategy:
matrix:
include:
- os: macos-latest
suffix: ''
target: x86_64-apple-darwin
install: ''
- os: ubuntu-latest
suffix: ''
target: x86_64-unknown-linux-gnu
install: ''
- os: windows-latest
suffix: .exe
target: x86_64-pc-windows-msvc
install: ''

tag-and-release:
needs:
- build-binaries
- bump-cargo-version
uses: armakuni/github-actions/.github/workflows/[email protected]
with:
download-artifacts: true
release-artifacts: ./bins/*


74 changes: 74 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
on:
workflow_call:
outputs:
will-bump:
value: ${{ jobs.check-conventional-commits.outputs.will-bump }}
bump-version:
value: ${{ jobs.check-conventional-commits.outputs.bump-version }}

jobs:
check-conventional-commits:
uses: armakuni/github-actions/.github/workflows/[email protected]

cargo-audit:
runs-on: ubuntu-latest
steps:
- uses: tomphp/github-actions/[email protected]
- uses: actions-rs/[email protected]
name: Audit check cargo packages
with:
token: ${{ secrets.GITHUB_TOKEN }}

cargo-check:
runs-on: ubuntu-latest
steps:
- uses: tomphp/github-actions/[email protected]
- uses: actions-rs/[email protected]
with:
command: check

cargo-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: macos-latest
- os: ubuntu-latest
- os: windows-latest
steps:
- uses: tomphp/github-actions/[email protected]
- uses: specdown/[email protected]
- name: Rename wsl bash
if: runner.os == 'Windows'
run: |
takeown /F 'C:\Windows\System32\bash.exe'
icacls 'C:\Windows\System32\bash.exe' /grant administrators:F
ren 'C:\Windows\System32\bash.exe' wsl-bash.exe
- run: cargo build --release
- run: echo "$PWD/target/debug" >> "$GITHUB_PATH"
shell: bash
- run: cargo test --locked
shell: bash

lint:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
- os: windows-latest
steps:
- uses: tomphp/github-actions/[email protected]
with:
rust-components: rustfmt, clippy
- uses: actions-rs/[email protected]
with:
command: fmt
args: --all -- --check
- uses: actions-rs/[email protected]
with:
command: clippy
args: --all-targets --all-features -- -D warnings -Dclippy::all -D clippy::pedantic
-D clippy::cargo -A clippy::multiple-crate-versions
- uses: gaurav-nelson/[email protected]
if: matrix.os == 'ubuntu-latest'
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ clean:
rm -rf target/

.PHONY=check
check:
lint:
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings -D clippy::all -D clippy::pedantic -D clippy::cargo -A clippy::multiple-crate-versions
cargo check
Expand All @@ -23,7 +23,14 @@ format:

.PHONY=test-integration
test-integration: target/release/versioned-files
cargo test --test '*'
cargo test --test '*' --locked

.PHONY=test-unit
test-unit:
cargo test --bins --locked

.PHONY=test
test: test-integration
test: test-unit test-integration

.PHONY=precommit
precommit: lint test
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ versioned-files help

This will give you all the details you need:

```text, verify()
(Non-windows)
```text, verify(target_os="!windows")
A tool which updates files in your project with the current version number.
Usage: versioned-files <COMMAND>
Expand All @@ -76,6 +77,21 @@ Options:
-V, --version Print version
```

(Windows)
```text, verify(target_os="windows")
A tool which updates files in your project with the current version number.
Usage: versioned-files.exe <COMMAND>
Commands:
update Updates the version in all known locations
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
```

## Current Version

To find out what version you are running, you can run:
Expand Down
24 changes: 24 additions & 0 deletions cog.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
tag_prefix = "v"
from_latest_tag = false
ignore_merge_commits = true
branch_whitelist = ["main"]
pre_bump_hooks = []
post_bump_hooks = [
"git push",
"git push origin v{{version}}",
]
pre_package_bump_hooks = []
post_package_bump_hooks = []

[git_hooks]

[commit_types]

[changelog]
path = "CHANGELOG.md"
template = "remote"
remote = "github.com"
repository = "versioned-files"
owner = "tomphp"

authors = []

0 comments on commit 4b5e023

Please sign in to comment.