Skip to content

Commit

Permalink
improve obs-websocket protocol version releaser workflow thing (#99)
Browse files Browse the repository at this point in the history
* use semver of obs-websocket to determine our semver

* don't autolabel based on file changes

* protocol label

* yolo

---------

Co-authored-by: Andrey Kaipov <andreykaipov@users.noreply.github.com>
  • Loading branch information
andreykaipov and andreykaipov authored Dec 21, 2023
1 parent ff14e2f commit a98c9e7
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 49 deletions.
45 changes: 24 additions & 21 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
---
name-template: v$RESOLVED_VERSION 🌈
name-template: v$RESOLVED_VERSION
tag-template: v$RESOLVED_VERSION
tag-prefix: v

autolabeler:
- label: chore
files:
- 'docker/*'
- '*.sh'
- Makefile
branch:
- /chore\/.+/
- /ci\/.+/
- /docs\/.+/
title:
- /docs/i
branch: [/^chore\/.+/]
- label: ci
branch: [/^ci\/.+/]
- label: docs
branch: [/^docs\/.+/]
- label: fix
branch:
- /fix\/.+/
title:
- /fix/i
branch: [/^fix\/.+/]
- label: feature
branch:
- /feature\/.+/
files:
- version.go
branch: [/^feature\/.+/]
- label: major
branch: [/^major\/.+/]
- label: minor
branch: [/^minor\/.+/]
- label: patch
branch: [/^patch\/.+/]

categories:
- title: 🚨 Breaking Changes
labels:
- breaking
- title: 💻 Protocol Updates
labels:
- protocol
- title: 🚀 Features
labels:
- enhancement
Expand All @@ -41,7 +39,8 @@ categories:
- title: 🔧 Maintenance
labels:
- chore
- documentation
- ci
- docs
- title: 🤖 Dependencies
labels:
- dependencies
Expand All @@ -50,17 +49,21 @@ version-resolver:
major:
labels:
- breaking
- major
minor:
labels:
- enhancement
- feature
- minor
patch:
labels:
- bug
- chore
- ci
- dependencies
- documentation
- docs
- fix
- patch
default: patch

template: |
Expand Down
26 changes: 17 additions & 9 deletions .github/workflows/update-protocol-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,38 @@ jobs:
go-version-file: go.mod

- name: update version
id: update
id: update-version
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
run: |
./script/bump-protocol-version.sh
./script/update-readme-snippets.sh
version=$(grep ProtocolVersion version.go | tr -dc '0-9.')
message="Bump OBS websocket protocol to $version"
echo "message=$message" >>$GITHUB_OUTPUT
- name: create pr
id: create-pr
if: steps.update-version.outcome == 'success'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.generate-token.outputs.token }}
title: ${{ steps.update.outputs.message }}
commit-message: ${{ steps.update.outputs.message }}
branch: feature/bump-protocol-version
title: ${{ steps.update-version.outputs.message }}
commit-message: ${{ steps.update-version.outputs.message }}
branch: ${{ steps.update-version.outputs.bump }}/bump-protocol-version
delete-branch: true
labels: |
feature
${{ steps.update-version.outputs.bump }}
protocol
reviewers: |
andreykaipov
body: |
There was a new v5 tag in [obsproject/obs-websocket](https://github.com/obsproject/obs-websocket).
This PR may or may not contain any actual changes to the generated code.
- uses: release-drafter/release-drafter@v5
if: steps.create-pr.outcome == 'success'
with:
config-name: release-drafter.yml
disable-autolabeler: true
publish: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
81 changes: 62 additions & 19 deletions script/bump-protocol-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,74 @@

set -eu

tags=$(
gh api /repos/obsproject/obs-websocket/git/refs/tags -q .[].ref |
awk -F/ '/5[.][0-9]+[.][0-9]+/ {print $3}' |
grep -v - |
sort -Vr
)

current=$(grep ProtocolVersion version.go | tr -dc '0-9.')
next=$(echo "$tags" | sort -V | awk -v current="$current" '$0==current{getline;print;exit}')
latest=$(echo "$tags" | sort -V | tail -n1)

cat >&2 <<EOF
find_versions() {
tags=$(
gh api /repos/obsproject/obs-websocket/git/refs/tags -q .[].ref |
awk -F/ '/5[.][0-9]+[.][0-9]+/ {print $3}' |
grep -v - |
sort -Vr
)

current=$(grep ProtocolVersion version.go | tr -dc '0-9.')
next=$(echo "$tags" | sort -V | awk -v current="$current" '$0==current{getline;print;exit}')
latest=$(echo "$tags" | sort -V | tail -n1)

cat >&2 <<EOF
Current: $current
Next: $next
Latest: $latest
EOF

version_regex='^[0-9]+\.[0-9]+\.[0-9]+$'
version_regex='^[0-9]+\.[0-9]+\.[0-9]+$'

for v in "$current" "$next" "$latest"; do
if ! echo "$v" | grep -qE "$version_regex"; then
echo "Doesn't look like a version: $v"
exit 1
fi
done
}

for v in "$current" "$next" "$latest"; do
if ! echo "$v" | grep -qE "$version_regex"; then
echo "Doesn't look like a version: $v"
compare_versions() {
current_major=$(echo "$current" | cut -d. -f1)
current_minor=$(echo "$current" | cut -d. -f2)
current_patch=$(echo "$current" | cut -d. -f3)
next_major=$(echo "$next" | cut -d. -f1)
next_minor=$(echo "$next" | cut -d. -f2)
next_patch=$(echo "$next" | cut -d. -f3)

if [ "$next_major" -gt "$current_major" ]; then
bump=major
elif [ "$next_minor" -gt "$current_minor" ]; then
bump=minor
elif [ "$next_patch" -gt "$current_patch" ]; then
bump='patch'
else
echo "$current is not greater than $next"
echo "Nothing to update"
exit 1
fi
done

sed -i "s/$current/$next/g" version.go README.md
make generate
if [ -n "$GITHUB_ACTIONS" ]; then
echo "bump=$bump" >>"$GITHUB_OUTPUT"
echo "next=$next" >>"$GITHUB_OUTPUT"
fi
}

bump_versions() {
sed -i "s/$current/$next/g" version.go README.md
make generate

if [ -n "$GITHUB_ACTIONS" ]; then
message="Bump OBS websocket protocol to $next"
echo "message=$message" >>"$GITHUB_OUTPUT"
fi
}

main() {
find_versions
compare_versions
bump_versions
}

main "$@"

0 comments on commit a98c9e7

Please sign in to comment.