Skip to content

Commit 35d5d6b

Browse files
committed
multi: check compiled protos in GH actions
To make sure the compiled protos in the git repository are always up to date, we add a GitHub action that checks them by compiling and diffing the files.
1 parent f6b16e4 commit 35d5d6b

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

.github/workflows/main.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
branches:
99
- "*"
1010

11+
env:
12+
# go needs absolute directories, using the $HOME variable doesn't work here.
13+
DOWNLOAD_CACHE: /home/runner/work/download_cache
14+
1115
jobs:
1216
frontend:
1317
name: frontend tests on ${{ matrix.os }}
@@ -118,3 +122,54 @@ jobs:
118122

119123
- name: build backend binary
120124
run: make build
125+
126+
proto-compile-check:
127+
name: RPC proto compilation check
128+
runs-on: ubuntu-latest
129+
steps:
130+
- name: set git config
131+
run: |
132+
git config --global core.eol lf
133+
git config --global core.autocrlf false
134+
135+
- name: git checkout
136+
uses: actions/checkout@v2
137+
138+
- name: setup nodejs v${{ matrix.node_version }}
139+
uses: actions/setup-node@v1
140+
with:
141+
node-version: 12.x
142+
143+
- name: download cache
144+
uses: actions/cache@v1
145+
with:
146+
path: /home/runner/work/download_cache
147+
key: lnd-${{ runner.os }}-download-${{ hashFiles('**/install_protoc.sh') }}
148+
restore-keys: |
149+
lnd-${{ runner.os }}-download-${{ hashFiles('**/install_protoc.sh') }}
150+
lnd-${{ runner.os }}-download-
151+
152+
- name: install protoc and protobuf libraries
153+
run: ./scripts/install_protoc.sh
154+
155+
- name: get yarn cache dir
156+
id: yarn-cache-dir
157+
run: echo "::set-output name=dir::$(yarn cache dir)"
158+
159+
- name: yarn cache
160+
uses: actions/cache@v2
161+
id: yarn-cache
162+
with:
163+
path: ${{ steps.yarn-cache-dir.outputs.dir }}
164+
key: ${{ runner.os }}-yarn-${{ matrix.node_version }}-${{ hashFiles('**/yarn.lock') }}
165+
restore-keys: |
166+
${{ runner.os }}-yarn-${{ matrix.node_version }}-${{ hashFiles('**/yarn.lock') }}
167+
${{ runner.os }}-yarn-${{ matrix.node_version }}-
168+
${{ runner.os }}-yarn-
169+
170+
- name: install dependencies
171+
working-directory: ./app
172+
run: yarn
173+
174+
- name: run check
175+
run: make protos-check

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ list:
192192
grep -v Makefile | \
193193
sort
194194

195+
protos:
196+
@$(call print, "Compiling protos.")
197+
cd ./app; yarn protos
198+
199+
protos-check: protos
200+
@$(call print, "Verifying compiled protos.")
201+
if test -n "$$(git describe --dirty | grep dirty)"; then echo "Protos not properly formatted or not compiled with v3.4.0"; git status; git diff; exit 1; fi
202+
195203
clean:
196204
@$(call print, "Cleaning source.$(NC)")
197205
$(RM) ./lightning-terminal-debug

scripts/install_protoc.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
# Abort on error (-e) and print commands (-v).
4+
set -ev
5+
6+
# See README.md in lnrpc (of the lnd repository) why we need these specific
7+
# versions/commits.
8+
PROTOC_VERSION=3.4.0
9+
10+
# This script is specific to GitHub Actions so we only need to support linux x64.
11+
PROTOC_URL="https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip"
12+
PROTOC_DL_CACHE_DIR="${DOWNLOAD_CACHE:-/tmp/download_cache}/protoc"
13+
14+
# install_protoc copies the cached protoc binary to the $PATH or downloads it
15+
# if no cached version is found.
16+
install_protoc() {
17+
if [ -f "${PROTOC_DL_CACHE_DIR}/bin/protoc" ]; then
18+
echo "Using cached version of protoc"
19+
else
20+
wget -O /tmp/protoc.zip $PROTOC_URL
21+
mkdir -p "${PROTOC_DL_CACHE_DIR}"
22+
unzip -o /tmp/protoc.zip -d "${PROTOC_DL_CACHE_DIR}"
23+
chmod -R a+rx "${PROTOC_DL_CACHE_DIR}/"
24+
fi
25+
sudo cp "${PROTOC_DL_CACHE_DIR}/bin/protoc" /usr/local/bin
26+
sudo cp -r "${PROTOC_DL_CACHE_DIR}/include" /usr/local
27+
}
28+
29+
install_protoc

0 commit comments

Comments
 (0)