-
Notifications
You must be signed in to change notification settings - Fork 1
146 lines (140 loc) · 5.21 KB
/
publish-bufs.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: Publish Bufs
on:
push:
branches: [ 'main' ]
paths:
- proto/**/*.proto
- gen/*/proto/**/*
env:
# renovate: datasource=github-releases depName=bufbuild/buf
BUF_CLI_VERSION: '1.30.0'
NODE_VERSION: '18.x'
# renovate: datasource=dart-version depName=dart
DART_VERSION: '3.3.1'
jobs:
check-preconditions:
runs-on: ubuntu-22.04
outputs:
bump: ${{ steps.bump.outputs.bump }}
commit: ${{ steps.commit.outputs.sha }}
steps:
- name: Clone Repo
uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: bufbuild/buf-setup-action@v1.29.0
with:
version: ${{ env.BUF_CLI_VERSION }}
github_token: ${{ secrets.GITHUB_TOKEN }}
- uses: bufbuild/buf-lint-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# TODO (arm-versioning): Arm versioning by remove the comment of ONLY the next line
# - name: Check for illegal breakage
# Only deletions are allowed. Breaking updates must happen in a new version of the package(s) in question.
# This is just a sanity check!
# For example it allows you to delete files from the latest version of a package (depending on context that might even be ok).
# TODO (arm-versioning): Arm versioning by remove the comment of the next line
# run: buf breaking --against '.git#ref=HEAD^' --error-format json | jq .type | if grep -v -q \"FILE_NO_DELETE\"; then exit 1; fi
- name: Has breakage?
id: breaking
# We previously checked if any illegal breakage occurred, now check if we have breakage _at all_
# If so, we publish this as a _major_ release
run: buf breaking --against '.git#ref=HEAD^' && echo "breaking=false" >> $GITHUB_OUTPUT || echo "breaking=true" >> $GITHUB_OUTPUT
- name: Has new package?
id: new-package
run: |
last_tree=$(git ls-tree -d -r --name-only HEAD^ proto | sort) # directory tree of proto in old commit
current_tree=$(find proto -type d | sort) # directory tree of proto right now
new_dirs=$(comm -13 <(echo "$last_tree") <(echo "$current_tree")) # filter out lines, which are "-3": common (i.e. unchanged) or "-1": only in the last tree (i.e. removed)
echo $new_dirs
if [ -z "$new_dirs" ]; then
echo "new-package=false" >> $GITHUB_OUTPUT
else
echo "new-package=true" >> $GITHUB_OUTPUT
fi
- name: Get SHA
id: commit
run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Get Bump
id: bump
run: |
BUMP="patch"
if [ "$BREAKING" = "true" ]; then
# TODO (arm-versioning): Arm versioning by replacing the following "minor" with "major"
BUMP="minor"
elif [ "$NEW_PKG" = "true" ]; then
BUMP="minor"
else
BUMP="patch"
fi
echo "bump=$BUMP" >> $GITHUB_OUTPUT
env:
BREAKING: ${{ steps.breaking.outputs.breaking }}
NEW_PKG: ${{ steps.new-package.outputs.new-package }}
ts:
needs: check-preconditions
runs-on: ubuntu-22.04
permissions:
packages: write
steps:
- name: Clone Repo
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'
- name: Fetch latest version from registry
working-directory: gen/ts
run: npm version $(npm view . version)
- name: Bump version
working-directory: gen/ts
run: npm version pre$BUMP --preid $SHA
env:
BUMP: ${{ needs.check-preconditions.outputs.bump }}
SHA: ${{ needs.check-preconditions.outputs.commit }}
- run: npm publish --access public
working-directory: gen/ts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
dart:
needs:
- check-preconditions
- ts
runs-on: ubuntu-22.04
steps:
- name: Clone Repo
uses: actions/checkout@v4
with:
ref: main
- name: Install tools
run: |
wget -O /usr/local/bin/semver https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver
chmod +x /usr/local/bin/semver
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ env.DART_VERSION }}
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v2'
with:
version: '>= 363.0.0'
- name: Auth Service Account
uses: 'google-github-actions/auth@v2'
with:
credentials_json: ${{ secrets.PUB_DEV_KEY }}
- name: Set pub.dev token
run: |
gcloud auth print-identity-token --audiences=https://pub.dev | dart pub token add https://pub.dev
- name: Bump version
working-directory: gen/dart
env:
BUMP: ${{ needs.check-preconditions.outputs.bump }}
SHA: ${{ needs.check-preconditions.outputs.commit }}
run: |
VERSION=$(curl https://pub.dev/api/packages/helpwave_proto_dart -H "Accept: application/vnd.pub.v2+json" | jq ".latest.version" -r)
NEW_VERSION=$(semver bump $BUMP $VERSION)
NEW_VERSION=$(semver bump prerel $SHA.0 $NEW_VERSION)
sed "s/version:.*/version: $NEW_VERSION/" pubspec.yaml -i
- name: Publish to pub.dev
working-directory: gen/dart
run: dart pub publish -f