Skip to content

Release

Release #24

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
bumpLevel:
description: 'Version Bump Level'
required: true
default: 'patch'
type: choice
options:
- none
- major
- minor
- patch
dryRun:
description: 'Dry Run mode'
type: boolean
env:
CARGO_TERM_COLOR: always
jobs:
verify_build:
name: Verify build
runs-on: ubuntu-latest
steps:
- name: Print information
run: |
echo "Running deployment workflow"
echo "version level: ${BUMP_LEVEL}"
echo "dry-run: ${DRY_RUN}"
env:
BUMP_LEVEL: ${{ inputs.bumpLevel }}
DRY_RUN: ${{ inputs.dryRun }}
- uses: actions/checkout@v3
# - name: Ensure branch is 'main'
# run: |
# git fetch origin &> /dev/null
# branch="$(git rev-parse --abbrev-ref HEAD)"
# if [[ "${branch}" != "main" ]]; then
# echo "The release branch must be main. Got '${branch}'' instead." >&2
# exit 1
# else
# echo "Branch is '${branch}'"
# fi
- name: Build
run: cargo build --verbose --all-features --all
- name: Run tests
run: cargo test --verbose --all-features --all
- name: Run clippy
run: cargo clippy --verbose --all-features --all -- -D warnings
bump_version:
if: ${{ inputs.bumpLevel != 'none'}}
name: Bump version
runs-on: ubuntu-latest
needs: verify_build
outputs:
version: ${{ steps.check_version.outputs.version }}
tag: ${{ steps.check_version.outputs.tag }}
commit: ${{ steps.check_version.outputs.commit }}
previous_version: ${{ steps.bump_version.outputs.previous_version }}
steps:
- uses: actions/checkout@v3
- name: Install tq
run: |
wget https://github.com/4rbor/tq/releases/download/0.1.4-75/tq-lin.tar.gz -O - | tar -xz
mv tq /usr/local/bin
- run: |
echo "Bumping to level: $BUMP_LEVEL"
env:
BUMP_LEVEL: ${{ inputs.bumpLevel }}
- name: Install python requirements
run: |
echo "PWD: ${PWD}" && ls && pip3 install -r requirements.txt
- name: Bump appropriate version
id: bump_version
run: |
PREVIOUS_VERSION=$(tq -f Cargo.toml .package.version | sed 's/^.\(.*\).$/\1/')
echo "previous_version=${PREVIOUS_VERSION}" >> $GITHUB_OUTPUT
python3 new_version.py ${{ inputs.bumpLevel }}
- name: Show diff
run: git diff
- name: Compute version and ensure release does not already exist
id: check_version
run: |
VERSION=$(tq -f Cargo.toml .package.version | sed 's/^.\(.*\).$/\1/')
TAG="v${VERSION}"
COMMIT=$(git rev-parse HEAD)
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "commit=${COMMIT}" >> $GITHUB_OUTPUT
echo "Checking versions:"
echo "Version: ${VERSION}"
echo "Previous version: ${PREVIOUS_VERSION}"
echo "Tag: ${TAG}"
git fetch origin &> /dev/null
if [[ -n "$(git tag -l ${TAG})" ]]; then
echo "A release '${TAG}' already exists." >&2
exit 1
else
echo "Tag '${TAG}' will be created on successful deploy"
fi
env:
PREVIOUS_VERSION: ${{ steps.bump_version.outputs.previous_version }}
- name: Configure git
run: |
git config --global user.name 'Ricardo Delfin'
git config --global user.email '[email protected]'
- name: Commit version
run: |
VERSION=$(tq -f Cargo.toml .package.version | sed 's/^.\(.*\).$/\1/')
git commit -am "release version ${VERSION}"
- name: Push new version
run: |
git push
publish_crates:
name: Publish crates.io
runs-on: ubuntu-latest
needs: bump_version
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.bump_version.outputs.commit }}
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: katyo/publish-crates@v2
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
args: --package flatbuffers-build
dry-run: ${{ inputs.dryRun }}
check-repo: ${{ inputs.dryRun }}
no-verify: ${{ inputs.dryRun }}
github_release:
name: Generate Github release
runs-on: ubuntu-latest
needs: [publish_crates, bump_version]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.bump_version.outputs.commit }}
- name: Generate changelog
id: github_changelog
uses: mikepenz/release-changelog-builder-action@v4
with:
fromTag: v${{ needs.bump_version.outputs.previous_version }}
toTag: ${{ needs.bump_version.outputs.commit }}
outputFile: ${{ github.workspace }}/.github/changelog.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate release notes
run: |
# Generate the release notes
echo "Generating release notes..."
echo ""
echo "Changelog: "
cat ${{ github.workspace }}/.github/changelog.txt
echo ""
cat ${{ github.workspace }}/.github/release_notes.template ${{ github.workspace }}/.github/changelog.txt \
| sed 's/{version}/${{ env.VERSION }}/g' \
> ${{ github.workspace }}/.github/release_notes.txt
env:
VERSION: ${{ needs.bump_version.outputs.version }}
- name: Create release
uses: softprops/action-gh-release@v1
id: rules_rust_release
env:
GIT_TAG: ${{ needs.bump_version.outputs.tag }}
COMMIT: ${{ needs.bump_version.outputs.commit }}
with:
generate_release_notes: true
tag_name: ${{ env.GIT_TAG }}
body_path: ${{ github.workspace }}/.github/release_notes.txt
target_commitish: ${{ env.COMMIT }}