Skip to content

Commit 566f359

Browse files
authored
Windows 32/64 Github Action Builds (#166)
* Add windows bazel build github action * Refactor window-build to support all cpus * Disable linux and mac OS builds as they continue to function in existing build system * Updates from code review removing setup-protoc dep
1 parent 6113588 commit 566f359

File tree

5 files changed

+183
-10
lines changed

5 files changed

+183
-10
lines changed

.github/workflows/build.yml

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: Build, Test and Release
2+
3+
on: push
4+
5+
permissions: read-all
6+
7+
# update in build.yml and codeql.yml at same time
8+
env:
9+
PROTOC_VERSION: 21.3
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
env:
16+
PROTOC: protoc-release/bin/protoc
17+
PROTOC_INC: protoc-release/include
18+
PROTOC_PLATFORM: linux-x86_64
19+
20+
steps:
21+
22+
- uses: actions/checkout@v3
23+
24+
- uses: actions/setup-node@v3
25+
with:
26+
token: ${{ secrets.GITHUB_TOKEN }}
27+
node-version: 16
28+
cache: ${{ !env.ACT && 'npm' || '' }} # cache API not available in ACT
29+
30+
- uses: bazelbuild/setup-bazelisk@v2
31+
with:
32+
token: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Install Protoc
35+
run: |
36+
echo "Fetching protoc"
37+
curl --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
38+
-L https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${PROTOC_PLATFORM}.zip \
39+
--output protoc-release.zip
40+
unzip protoc-release.zip -d protoc-release
41+
rm protoc-release.zip
42+
43+
- run: npm ci
44+
45+
- run: npm test
46+
47+
- run: npm run build
48+
49+
- uses: actions/upload-artifact@v3
50+
with:
51+
name: js
52+
path: |
53+
google-protobuf.js
54+
google
55+
56+
package:
57+
needs: build
58+
runs-on: ${{ matrix.os }}
59+
60+
strategy:
61+
fail-fast: false
62+
matrix:
63+
# for now I'm disabling linux building as we don't have the tooling to support it
64+
# os: [ ubuntu-latest ]
65+
# cpu:
66+
# - k8 # this build 'linux-x86_64', is currently working but not useful without the other architectures
67+
# would need some kind of CROSSTOOL chain to build the other architectures
68+
# or we'd have to use the https://github.com/uraimo/run-on-arch-action (which lacks support for x86_32) to build these
69+
# - x86_32
70+
# - systemz
71+
# - aarch64
72+
# - ppc64
73+
include:
74+
# to ensure backwards compatibility as long as possible, use earliest versions of OSs available on Github Actions
75+
- os: windows-2019
76+
cpu: x64_windows
77+
bazel_target: dist_zip
78+
- os: windows-2019
79+
cpu: x64_x86_windows
80+
bazel_target: dist_zip
81+
# disabling Mac OS releases for now since they are working through existing build process
82+
# - os: macos-11
83+
# cpu: darwin_arm64
84+
# - os: macos-11
85+
# cpu: darwin_x86_64
86+
87+
steps:
88+
- uses: actions/checkout@v3
89+
90+
- uses: actions/download-artifact@v3
91+
if: ${{ !env.ACT }}
92+
with:
93+
name: js
94+
95+
- uses: bazelbuild/setup-bazelisk@v2
96+
with:
97+
token: ${{ secrets.GITHUB_TOKEN }}
98+
99+
- run: mkdir out
100+
101+
# setup-bazelisk fails when running in ACT because the cache is not available so we need to ignore to let the bazel step run
102+
- if: success() || env.ACT && failure()
103+
run: bazel build --cpu=${{ matrix.cpu }} ${{ matrix.bazel_target || 'dist_all' }}
104+
shell: bash
105+
106+
# need to copy to output directory as `bazel-bin` is a symlink and cannot be read by the actions/upload-artifact action
107+
- run: cp bazel-bin/protobuf-javascript-* out/
108+
109+
- uses: actions/upload-artifact@v3
110+
with:
111+
name: releases
112+
path: out
113+
114+
release:
115+
needs: package
116+
if: startsWith(github.ref, 'refs/tags/')
117+
118+
runs-on: ubuntu-latest
119+
permissions:
120+
contents: write
121+
122+
steps:
123+
- uses: actions/download-artifact@v3
124+
with:
125+
name: releases
126+
127+
- name: Release
128+
uses: svenstaro/upload-release-action@v2
129+
with:
130+
repo_token: ${{ secrets.GITHUB_TOKEN }}
131+
file: protobuf-javascript-*
132+
file_glob: true
133+
tag: ${{ github.ref }}
134+
overwrite: true

.github/workflows/codeql.yml

+22-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ name: "CodeQL"
1313

1414
permissions: read-all
1515

16+
# update in build.yml and codeql.yml at same time
17+
env:
18+
PROTOC_VERSION: 21.3
19+
1620
on:
1721
push:
1822
branches: [ "main" ]
@@ -38,6 +42,11 @@ jobs:
3842
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
3943
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
4044

45+
env:
46+
PROTOC: protoc-release/bin/protoc
47+
PROTOC_INC: protoc-release/include
48+
PROTOC_PLATFORM: linux-x86_64
49+
4150
steps:
4251
- name: Checkout repository
4352
uses: actions/checkout@v3
@@ -50,22 +59,26 @@ jobs:
5059
# If you wish to specify custom queries, you can do so here or in a config file.
5160
# By default, queries listed here will override any specified in a config file.
5261
# Prefix the list here with "+" to use these queries and those in the config file.
53-
62+
5463
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
5564
# queries: security-extended,security-and-quality
5665

5766

5867
# ℹ️ Command-line programs to run using the OS shell.
5968
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
6069

61-
- run: |
62-
echo "Fetch protoc"
63-
curl -L https://github.com/protocolbuffers/protobuf/releases/download/v21.3/protoc-21.3-linux-x86_64.zip --output $GITHUB_WORKSPACE/protoc-release.zip
64-
unzip $GITHUB_WORKSPACE/protoc-release.zip -d $GITHUB_WORKSPACE/protoc-release
65-
echo "Clean, install, and test protobuf-javascript"
66-
npm ci
67-
npm install
68-
PROTOC=$GITHUB_WORKSPACE/protoc-release/bin/protoc PROTOC_INC=$GITHUB_WORKSPACE/protoc-release/include npm test
70+
- name: Install Protoc
71+
run: |
72+
echo "Fetching protoc"
73+
curl --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
74+
-L https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${PROTOC_PLATFORM}.zip \
75+
--output protoc-release.zip
76+
unzip protoc-release.zip -d protoc-release
77+
rm protoc-release.zip
78+
79+
- run: npm ci
80+
81+
- run: npm test
6982

7083
- name: Perform CodeQL Analysis
7184
uses: github/codeql-action/analyze@v2

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.idea
2-
/node_modules/
2+
node_modules
33
commonjs_out
44
google/protobuf
55
bazel-*

BUILD.bazel

+21
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,29 @@ load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files", "strip_prefix")
66
load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip")
77
load("//:protobuf_javascript_release.bzl", "package_naming")
88

9+
config_setting(
10+
name = "x64_x86_windows",
11+
values = {"cpu": "x64_x86_windows"},
12+
)
13+
14+
config_setting(
15+
name = "x64_windows",
16+
values = {"cpu": "x64_windows"},
17+
)
18+
19+
config_setting(
20+
name = "k8",
21+
values = {"cpu": "k8"},
22+
)
23+
924
package_naming(
1025
name = "protobuf_javascript_pkg_naming",
26+
platform = select({
27+
":k8": "linux-x86_64", # currently the only supported build type in Github Actions
28+
":x64_x86_windows": "win32",
29+
":x64_windows": "win64",
30+
"//conditions:default": "" # continues with current behavior when no --cpu is specified allowing existing internal builds to function
31+
})
1132
)
1233

1334
pkg_files(

protobuf_javascript_release.bzl

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ def _package_naming_impl(ctx):
1010
values = {}
1111
values["version"] = _PROTOBUF_JAVASCRIPT_VERSION
1212

13+
if ctx.attr.platform != "":
14+
values["platform"] = ctx.attr.platform
15+
return PackageVariablesInfo(values=values)
16+
1317
# infer from the current cpp toolchain.
1418
toolchain = find_cpp_toolchain(ctx)
1519
cpu = toolchain.cpu
@@ -46,6 +50,7 @@ package_naming = rule(
4650
"_cc_toolchain":
4751
attr.label(
4852
default=Label("@bazel_tools//tools/cpp:current_cc_toolchain"),),
53+
"platform": attr.string(),
4954
},
5055
toolchains=["@bazel_tools//tools/cpp:toolchain_type"],
5156
incompatible_use_toolchain_transition=True,

0 commit comments

Comments
 (0)