Skip to content

Commit

Permalink
Deploy workflow (#2)
Browse files Browse the repository at this point in the history
* Corrected condition again

* More corrected syntax

* More syntax fun

* More syntax fixes

* Single quotation marks are like, so in right now

* Fixed names

* Fixed release note logic

* Syntax error

* Typo

* Fixed release script

* Syntax

* Added more logging

* Removed 'required' from input

* Expanded dryrun

* Removed publish step

* Minor fixes

* Productionised
  • Loading branch information
rdelfin authored Mar 31, 2024
1 parent 85198e1 commit caa79fe
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 18 deletions.
14 changes: 14 additions & 0 deletions .github/release_notes.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# {version}

This crate provides a set of functions to facilitate compiling flatbuffers to Rust from within
Rust. This is particularly helpful for use in `build.rs` scripts. Please note that for
compatiblity this crate will only support a single version of the `flatc` compiler. Please
check what version that is against whatever version is installed on your system.That said, due
to flatbuffers' versioning policy, it could be ok to mix patch and even minor versions.

Please read our [`README`](https://github.com/rdelfin/flatbuffers-build/blob/main/README.md) or
our [Rust docs](https://docs.rs/flatbuffers-build/latest/flatbuffers-build/) for more details on
how to use this crate.

# Changelog:

82 changes: 64 additions & 18 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ on:
- patch
dryRun:
description: 'Dry Run mode'
required: true
type: boolean

env:
Expand All @@ -26,17 +25,27 @@ jobs:
name: Verify build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Ensure branch is 'main'
- name: Print information
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
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
Expand All @@ -45,16 +54,22 @@ jobs:
run: cargo clippy --verbose --all-features --all -- -D warnings

bump_version:
if: inputs.bumpLevel !== none
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:
Expand All @@ -64,7 +79,11 @@ jobs:
echo "PWD: ${PWD}" && ls && pip3 install -r requirements.txt
- name: Bump appropriate version
run: python3 new_version.py ${{ inputs.bumpLevel }}
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
Expand All @@ -78,13 +97,19 @@ jobs:
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: |
Expand All @@ -93,18 +118,21 @@ jobs:
- name: Commit version
run: |
git commit -am "${{ inputs.bumpLevel }} version bump"
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:
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
Expand All @@ -114,21 +142,39 @@ jobs:
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: [bump_version, docker_build]
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
sed 's/{version}/${{ env.VERSION }}/g' ${{ github.workspace }}/.github/release_notes.template \
> ${{ github.workspace }}/.github/release_notes.txt
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 }}

Expand Down

0 comments on commit caa79fe

Please sign in to comment.