Skip to content

Commit 2afe8a8

Browse files
committed
Try generate files
1 parent d47aa9f commit 2afe8a8

File tree

4 files changed

+137
-45
lines changed

4 files changed

+137
-45
lines changed

.github/workflows/publish-new-go-sdik.yml renamed to .github/workflows/publish-new-go-sdk.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name: Create go-sdk version tag
1+
name: Publish Go SDK version tag
22
on:
3-
pull_request:
4-
# push:
5-
# branches:
6-
# - master
7-
# paths:
8-
# - 'sdk/**'
3+
push:
4+
branches:
5+
- master
6+
paths:
7+
- 'sdk/**'
8+
99
jobs:
1010
build:
1111
runs-on: ubuntu-latest

.github/workflows/update-buf.yml

-38
This file was deleted.

.github/workflows/update-go-sdk.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Update Go SDK
2+
on:
3+
pull_request:
4+
# workflow_dispatch:
5+
# inputs:
6+
# buf_version:
7+
# description: 'version'
8+
# required: true
9+
10+
jobs:
11+
update-buf-dependency:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Setup Go
16+
uses: actions/setup-go@v4
17+
with:
18+
go-version-file: 'sdk/go.mod'
19+
- name: Update buf
20+
run: |
21+
go get -u buf.build/gen/go/formal/admin/bufbuild/connect-go
22+
go run main.go
23+
mv sdk.go sdk/sdk.go
24+
cd sdk
25+
go get -u buf.build/gen/go/formal/admin/bufbuild/connect-go
26+
go get -u buf.build/gen/go/formal/admin/protocolbuffers/go
27+
- name: Bump Up Version
28+
run: |
29+
./bump_version.sh
30+
- uses: tibdex/github-app-token@v2
31+
id: generate-token
32+
with:
33+
app_id: ${{ secrets.APP_ID }}
34+
private_key: ${{ secrets.APP_PRIVATE_KEY }}
35+
# - name: Create Pull Request
36+
# uses: peter-evans/create-pull-request@v5
37+
# with:
38+
# base: master
39+
# token: ${{ steps.generate-token.outputs.token }}
40+
# title: "Bump Up Go SDK"
41+
# body: "Bump up Go SDK version. New tag will be created automatically after merge."

bump_version.sh

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env bash
2+
3+
# Usage: ./bump_version.sh -r <patch|minor|major> - Increments version by chosen release type.
4+
function help() {
5+
echo "Usage: ./bump_version.sh -r <patch|minor|major> - Increments version by chosen release type."
6+
echo ""
7+
echo "Flags:"
8+
echo "-r: release type (patch, minor, major)"
9+
echo "-h: help"
10+
}
11+
12+
# get version from version file
13+
VERSION=$(cat VERSION | tr -d '\n')
14+
15+
# r flag is for release
16+
while getopts ":r:h" opt; do
17+
case $opt in
18+
r)
19+
RELEASE=$OPTARG
20+
;;
21+
h)
22+
help
23+
exit 0
24+
;;
25+
\?)
26+
echo "Invalid option: -$OPTARG" >&2
27+
;;
28+
esac
29+
done
30+
31+
# if release flag is not set, exit
32+
if [ -z "$RELEASE" ]; then
33+
echo "No release flag set. Aborting."
34+
help
35+
exit 1
36+
fi
37+
38+
# bump version (version, release)
39+
function bump_version(){
40+
major=$(echo "$1" | cut -d'.' -f1)
41+
minor=$(echo "$1" | cut -d'.' -f2)
42+
patch=$(echo "$1" | cut -d'.' -f3)
43+
44+
case "$2" in
45+
"major")
46+
major=$((major+1))
47+
minor=0
48+
patch=0
49+
;;
50+
"minor")
51+
minor=$((minor+1))
52+
patch=0
53+
;;
54+
"patch")
55+
patch=$((patch+1))
56+
;;
57+
esac
58+
59+
echo "$major.$minor.$patch"
60+
}
61+
62+
function confirm() {
63+
read -r -p "$@ [Y/n]: " confirm
64+
65+
case "$confirm" in
66+
[Nn][Oo]|[Nn])
67+
echo "Aborting."
68+
exit
69+
;;
70+
esac
71+
}
72+
73+
# convert release flag to lowercase
74+
RELEASE=$(echo "$RELEASE" | tr '[:upper:]' '[:lower:]')
75+
# if release flag is not patch, minor, or major, exit
76+
if [ "$RELEASE" != "patch" ] && [ "$RELEASE" != "minor" ] && [ "$RELEASE" != "major" ]; then
77+
echo "Invalid release flag. Aborting."
78+
exit 1
79+
fi
80+
81+
# update version
82+
VERSION=$(bump_version "$VERSION" "$RELEASE")
83+
confirm "Updating version to $VERSION ?"
84+
85+
# update version in version file
86+
echo $VERSION > ./VERSION
87+
88+
echo $VERSION
89+
export VERSION=$VERSION

0 commit comments

Comments
 (0)