Skip to content

Commit

Permalink
Add workflows for bumping versions and releasing (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
njooma authored Jul 31, 2023
1 parent d2c874d commit 17b2bd3
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 7 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ on:
workflow_dispatch:
push:
paths:
- 'lib/**'
- 'doc/**'
- 'README.md'
- 'dartdoc_options.yaml'
branches: [ main ]
- "lib/**"
- "doc/**"
- "README.md"
- "dartdoc_options.yaml"
branches: [main]

jobs:
generate-docs:
if: github.repository_owner == 'viamrobotics'
runs-on: [self-hosted, x64]
container:
image: ghcr.io/cirruslabs/flutter:3.10.5
image: ghcr.io/cirruslabs/flutter:3.10.6
steps:
- name: Checkout Push/Workflow Dispatch
uses: actions/checkout@v3
Expand Down Expand Up @@ -43,4 +43,3 @@ jobs:
with:
name: html-docs
path: html-docs.zip

10 changes: 10 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Publish to pub.dev

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"

jobs:
publish:
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
87 changes: 87 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Release

on:
workflow_dispatch:

jobs:
prepare:
if: github.repository_owner == 'viamrobotics' && startsWith(github.ref_name, 'rc-')
runs-on: [self-hosted, x64]
container:
image: ghcr.io/cirruslabs/flutter:3.10.6
outputs:
version: ${{ steps.which_version.outputs.version }}
steps:
- name: Check if organization member
id: is_organization_member
uses: jamessingleton/[email protected]
with:
organization: viamrobotics
username: ${{ github.actor }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Cancelling - not an organization member
uses: andymckay/[email protected]
if: steps.is_organization_member.outputs.result == 'false'

- name: Checkout Code
uses: actions/checkout@v3

- name: Setup Flutter
run: flutter pub get

- run: make setup

- name: Format + Lint + Test
run: make format lint test

- name: Bump Version
shell: bash
run: PATH=$PATH:$HOME/.pub-cache/bin cider bump release

- name: Which Version
id: which_version
shell: bash
run: PATH=$PATH:$HOME/.pub-cache/bin echo "version=$(cider version | sed -e 's/\"//g' -e 's/-rc.*//g')" >> $GITHUB_OUTPUT

- name: Check if release exists
uses: cardinalby/[email protected]
id: release_exists
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
releaseName: v${{ steps.which_version.outputs.version }}
doNotFailIfNotFound: "true"

- name: Cancelling - release already exists
uses: andymckay/[email protected]
if: steps.release_exists.outputs.id != ''

- name: Add + Commit
uses: EndBug/add-and-commit@v9
with:
new_branch: rc-${{ steps.which_version.outputs.version }}
message: Bump version to ${{ steps.which_version.outputs.version }}

- name: Open PR
uses: repo-sync/pull-request@v2
with:
destination_branch: "main"
pr_title: ${{ steps.which_version.outputs.version }}
pr_body: This is an auto-generated PR to merge the rc branch back into main upon successful release.

release:
needs: [prepare]
if: github.repository_owner == 'viamrobotics' && startsWith(github.ref_name, 'rc-')
runs-on: [self-hosted, x64]
container:
image: ghcr.io/viamrobotics/canon:amd64

steps:
- name: Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.prepare.outputs.version }}
draft: true
prerelease: false
target_commitish: rc-${{ needs.prepare.outputs.version }}
122 changes: 122 additions & 0 deletions .github/workflows/release_candidate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Release Candidate

on:
workflow_dispatch:
inputs:
version:
description: "The type of version bump. If the current version is already RC, then the bump type is ignored and only the RC is increased. If nobump is selected, there is no RC increase. Ex: Current Version (CV): 0.0.1, type: patch, result: 0.0.2-rc.1. CV: 0.0.2-rc.1, type: patch, result: 0.0.2-rc.2. See https://github.com/f3ath/cider#bumping-the-project-version"
type: choice
required: true
default: nobump
options:
- major
- minor
- patch
- nobump

jobs:
prepare:
if: github.repository_owner == 'viamrobotics'
runs-on: [self-hosted, x64]
container:
image: ghcr.io/cirruslabs/flutter:3.10.6
outputs:
rc_version: ${{ steps.which_version.outputs.rc_version }}
version: ${{ steps.which_version.outputs.version }}
steps:
- name: Check if organization member
id: is_organization_member
uses: jamessingleton/[email protected]
with:
organization: viamrobotics
username: ${{ github.actor }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Cancelling - not an organization member
uses: andymckay/[email protected]
if: steps.is_organization_member.outputs.result == 'false'

- name: Install GH CLI
run: |
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
- name: Checkout Code
uses: actions/checkout@v3

- name: Setup Flutter
run: flutter pub get

- run: make setup

- name: Format + Lint + Test
run: make format lint test

- name: Current version
id: current_version
shell: bash
run: |
PATH=$PATH:$HOME/.pub-cache/bin echo "current_version=$(cider version)" >> $GITHUB_OUTPUT
- name: Bump Version
id: bump_version
if: inputs.version != 'nobump'
shell: bash
run: |
if ${{ contains(steps.current_version.outputs.current_version, 'rc') }} ; then
PATH=$PATH:$HOME/.pub-cache/bin cider bump pre
else
PATH=$PATH:$HOME/.pub-cache/bin cider bump ${{ inputs.version }} --pre=rc
fi
- name: Which Version
id: which_version
shell: bash
run: |
PATH=$PATH:$HOME/.pub-cache/bin echo "rc_version=$(cider version | sed 's/\"//g')" >> $GITHUB_OUTPUT
PATH=$PATH:$HOME/.pub-cache/bin echo "version=$(cider version | sed -e 's/\"//g' -e 's/-rc.*//g')" >> $GITHUB_OUTPUT
- name: Check if release exists
uses: cardinalby/[email protected]
id: release_exists
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
releaseName: v${{ steps.which_version.outputs.rc_version }}
doNotFailIfNotFound: "true"

- name: Cancelling - release already exists
uses: andymckay/[email protected]
if: steps.release_exists.outputs.id != ''

- name: Add + Commit
uses: EndBug/add-and-commit@v9
with:
new_branch: rc-${{ steps.which_version.outputs.version }}
message: Bump version to ${{ steps.which_version.outputs.rc_version }}

- name: Open PR
run: |
gh pr create -t "rc-${{ steps.which_version.outputs.version }}" -b "This is an auto-generated PR to merge the RC branch back into main upon successful release" -B "main" -H "rc-${{ steps.which_version.outputs.version }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

release:
needs: [prepare]
if: github.repository_owner == 'viamrobotics'
runs-on: [self-hosted, x64]
container:
image: ghcr.io/viamrobotics/canon:amd64

steps:
- name: Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.prepare.outputs.rc_version }}
draft: true
prerelease: true
target_commitish: rc-${{ needs.prepare.outputs.version }}
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ buf: buf.yaml buf.gen.yaml
setup:
dart pub global activate protoc_plugin
dart pub global activate grpc
dart pub global activate cider

format:
dart format --line-length=140 --set-exit-if-changed $$(find . -name "*.dart" -not -path "./lib/src/gen/*" -not -path "**.mocks.dart")
Expand Down

0 comments on commit 17b2bd3

Please sign in to comment.