Skip to content

Commit

Permalink
Add github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
rlebran committed Sep 13, 2023
1 parent 0b4c72e commit f1d9e5e
Show file tree
Hide file tree
Showing 5 changed files with 282 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/actions/gitlog/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Git log
description: Mangles git log for change log
inputs:
output-file:
description: File path where to place the content of the changed commits
required: true
crate:
description: Name of the crate to get git log for
required: true
outputs:
last_release:
description: Last release commit or first commit of history
value: ${{ steps.gitlog.outputs.last_release }}
runs:
using: composite
steps:
- shell: bash
id: gitlog
run: |
${{ github.action_path }}/gitlog.sh --output-file ${{ inputs.output-file }} --crate ${{ inputs.crate }}
62 changes: 62 additions & 0 deletions .github/actions/gitlog/gitlog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

# This mangles git log entries for change lop purposes

output_file=""
while true; do
case $1 in
"--output-file")
shift
output_file="$1"
shift
;;
*)
break
;;
esac
done

if [[ "$output_file" == "" ]]; then
echo "Missing --output-file <file> option argument, define path to file or - for stdout" && exit 1
fi

from_commit=HEAD
last_release=$(git tag --sort=-committerdate | head -1)
echo "Found tag: $last_release"
if [[ "$last_release" == "" ]]; then
last_release=$(git tag --sort=-committerdate | head -1) # get last tag
echo "Using latest tag: $last_release"
fi

commit_range=""
if [[ $last_release != "" ]]; then
commit_range="$from_commit...$last_release"
else
commit_range="$from_commit"
fi

ancestry_path=""
if [[ "$last_release" != "" ]]; then
ancestry_path="--ancestry-path"
fi

mapfile -t log_lines < <(git log --pretty=format:'(%h) %s' $ancestry_path $commit_range)

log=""
for line in "${log_lines[@]}"; do
commit=$(echo "$line" | awk -F ' ' '{print $1}')
commit=${commit//[\(\)]/}
done

if [[ "$output_file" != "" ]]; then
if [[ "$output_file" == "-" ]]; then
echo -e "$log"
else
echo -e "$log" > "$output_file"
fi
fi

if [[ "$last_release" == "" ]]; then
last_release=$(git rev-list --reverse HEAD | head -1)
fi
echo "::set-output name=last_release::$last_release"
95 changes: 95 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: garde-actix-web build

on:
pull_request:
branches: [ main ]
paths:
- "**.rs"
- "**Cargo.toml"
push:
branches:
- main
paths:
- "**.rs"
- "**Cargo.toml"
workflow_dispatch:
env:
CARGO_TERM_COLOR: always

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
test:
strategy:
matrix:
crate:
- netwopenapi
- netwopenapi-gen
- netwopenapi-models
fail-fast: true

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2

- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Resolve changed paths
id: changes
run: |
changes=false
while read -r change; do
if [[ "$change" == "netwopenapi-gen" && "${{ matrix.crate }}" == "netwopenapi-gen" && $changes == false ]]; then
changes=true
elif [[ "$change" == "netwopenapi-models" && "${{ matrix.crate }}" == "netwopenapi-models" && $changes == false ]]; then
changes=true
elif [[ "$change" == "netwopenapi" && "${{ matrix.crate }}" == "netwopenapi" && $changes == false ]]; then
changes=true
fi
done < <(git diff --name-only ${{ github.sha }}~ ${{ github.sha }} | grep .rs | awk -F \/ '{print $1}')
echo "${{ matrix.crate }} changes: $changes"
echo "changes=$changes" >> $GITHUB_OUTPUT
- name: Check format
run: |
if [[ ${{ steps.changes.outputs.changes }} == true ]]; then
rustup component add rustfmt
cargo fmt --all --check --package ${{ matrix.crate }}
fi
- name: Check cranky
run: |
if [[ ${{ steps.changes.outputs.changes }} == true ]]; then
rustup component add clippy
cargo install cargo-cranky --force
cargo cranky --no-deps --all-features --tests --package ${{ matrix.crate }} -- -D warnings -D clippy::print_stdout
fi
- name: Check deny
run: |
if [[ ${{ steps.changes.outputs.changes }} == true ]]; then
cargo install cargo-deny --force
cargo deny check licenses sources advisories --package ${{ matrix.crate }}
fi
- name: Run tests
run: |
if [[ ${{ steps.changes.outputs.changes }} == true ]]; then
cargo test --all-features --package ${{ matrix.crate }}
fi
83 changes: 83 additions & 0 deletions .github/workflows/draft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Draft release

on:
push:
branches:
- main

env:
CARGO_TERM_COLOR: always

jobs:
draft:
strategy:
matrix:
crate:
- netwopenapi
- netwopenapi-gen
- netwopenapi-models
fail-fast: true
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: ./.github/actions/gitlog
name: Get changed commits
id: gitlog
with:
output-file: ./draft-gitlog.md
crate: ${{ matrix.crate }}

- name: Prepare changes
run: |
echo "## What's New :gem: :new: :tada:" > ./draft-changes.md
cat < ./draft-gitlog.md >> ./draft-changes.md
- name: Get release info
id: release_info
run: |
module="${{ matrix.crate }}"
version=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name | test("'"$module"'$")) | .version')
prerelease=false
if [[ "$version" =~ .*-.* ]]; then
prerelease=true
fi
echo "is_prerelease=$prerelease" >> $GITHUB_OUTPUT
echo "version=$version" >> $GITHUB_OUTPUT
- name: Add full change log link
run: |
echo -e "#### Full [change log](${{ github.server_url }}/${{ github.repository }}/compare/${{ steps.gitlog.outputs.last_release }}...${{ matrix.crate }}-${{ steps.release_info.outputs.version }})" >> ./draft-changes.md
- name: Check existing release
id: existing_release
run: |
if git tag | grep -e ^${{ matrix.crate }}-${{ steps.release_info.outputs.version }}$ > /dev/null; then
echo "Tag tag with ${{ matrix.crate }}-${{ steps.release_info.outputs.version }} already exists, cannot draft a release for already existing tag!, Consider upgrading versions to Cargo.toml file"
echo "is_new=false" >> $GITHUB_OUTPUT
else
echo "is_new=true" >> $GITHUB_OUTPUT
fi
- name: Remove previous release
if: ${{ steps.existing_release.outputs.is_new == 'true' }}
run: |
echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
gh release delete ${{ matrix.crate }}-${{ steps.release_info.outputs.version }} -y || true
- name: Create release
id: create_release
if: ${{ steps.existing_release.outputs.is_new == 'true' }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ matrix.crate }}-${{ steps.release_info.outputs.version }}
release_name: ${{ matrix.crate }}-${{ steps.release_info.outputs.version }}
body_path: ./draft-changes.md
draft: true
prerelease: ${{ steps.release_info.outputs.is_prerelease }}
22 changes: 22 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Publish release

on:
release:
types: [published]

env:
CARGO_TERM_COLOR: always

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2

- uses: katyo/publish-crates@v2
name: Cargo publish
with:
registry-token: ${{ secrets.CARGO_LOGIN }}

0 comments on commit f1d9e5e

Please sign in to comment.