Skip to content

Windows 32/64 Github Action Builds #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: Build, Test and Release

on: push

permissions: read-all

# update in build.yml and codeql.yml at same time
env:
PROTOC_VERSION: 21.3

jobs:
build:
runs-on: ubuntu-latest

env:
PROTOC: protoc-release/bin/protoc
PROTOC_INC: protoc-release/include
PROTOC_PLATFORM: linux-x86_64

steps:

- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
node-version: 16
cache: ${{ !env.ACT && 'npm' || '' }} # cache API not available in ACT

- uses: bazelbuild/setup-bazelisk@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Install Protoc
run: |
echo "Fetching protoc"
curl --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures we don't get rate capped for any reason (not that we would :))

-L https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${PROTOC_PLATFORM}.zip \
--output protoc-release.zip
unzip protoc-release.zip -d protoc-release
rm protoc-release.zip
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was no need for that whole $GITHUB_WORKSPACE stuff since it's all being executed in that directory as it is.


- run: npm ci

- run: npm test

- run: npm run build

- uses: actions/upload-artifact@v3
with:
name: js
path: |
google-protobuf.js
google
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These generated files should be the same no matter what platform we package the "protoc-gen-js/.exe" for so we can use the same assets


package:
needs: build
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
# for now I'm disabling linux building as we don't have the tooling to support it
# os: [ ubuntu-latest ]
# cpu:
# - k8 # this build 'linux-x86_64', is currently working but not useful without the other architectures
# would need some kind of CROSSTOOL chain to build the other architectures
# or we'd have to use the https://github.com/uraimo/run-on-arch-action (which lacks support for x86_32) to build these
# - x86_32
# - systemz
# - aarch64
# - ppc64
include:
# to ensure backwards compatibility as long as possible, use earliest versions of OSs available on Github Actions
- os: windows-2019
cpu: x64_windows
bazel_target: dist_zip
- os: windows-2019
cpu: x64_x86_windows
bazel_target: dist_zip
# disabling Mac OS releases for now since they are working through existing build process
# - os: macos-11
# cpu: darwin_arm64
# - os: macos-11
# cpu: darwin_x86_64

steps:
- uses: actions/checkout@v3

- uses: actions/download-artifact@v3
if: ${{ !env.ACT }}
with:
name: js

- uses: bazelbuild/setup-bazelisk@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}

- run: mkdir out

# setup-bazelisk fails when running in ACT because the cache is not available so we need to ignore to let the bazel step run
- if: success() || env.ACT && failure()
run: bazel build --cpu=${{ matrix.cpu }} ${{ matrix.bazel_target || 'dist_all' }}
shell: bash

# need to copy to output directory as `bazel-bin` is a symlink and cannot be read by the actions/upload-artifact action
- run: cp bazel-bin/protobuf-javascript-* out/

- uses: actions/upload-artifact@v3
with:
name: releases
path: out

release:
needs: package
if: startsWith(github.ref, 'refs/tags/')

runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/download-artifact@v3
with:
name: releases

- name: Release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: protobuf-javascript-*
file_glob: true
tag: ${{ github.ref }}
overwrite: true
31 changes: 22 additions & 9 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ name: "CodeQL"

permissions: read-all

# update in build.yml and codeql.yml at same time
env:
PROTOC_VERSION: 21.3

on:
push:
branches: [ "main" ]
Expand All @@ -38,6 +42,11 @@ jobs:
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

env:
PROTOC: protoc-release/bin/protoc
PROTOC_INC: protoc-release/include
PROTOC_PLATFORM: linux-x86_64

steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -50,22 +59,26 @@ jobs:
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# 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
# queries: security-extended,security-and-quality


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

- run: |
echo "Fetch protoc"
curl -L https://github.com/protocolbuffers/protobuf/releases/download/v21.3/protoc-21.3-linux-x86_64.zip --output $GITHUB_WORKSPACE/protoc-release.zip
unzip $GITHUB_WORKSPACE/protoc-release.zip -d $GITHUB_WORKSPACE/protoc-release
echo "Clean, install, and test protobuf-javascript"
npm ci
npm install
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm ci and npm install are the same except that npm install can modify the package-lock.json. npm ci does not so you should just use that.

PROTOC=$GITHUB_WORKSPACE/protoc-release/bin/protoc PROTOC_INC=$GITHUB_WORKSPACE/protoc-release/include npm test
- name: Install Protoc
run: |
echo "Fetching protoc"
curl --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
-L https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${PROTOC_PLATFORM}.zip \
--output protoc-release.zip
unzip protoc-release.zip -d protoc-release
rm protoc-release.zip

- run: npm ci

- run: npm test

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.idea
/node_modules/
node_modules
commonjs_out
google/protobuf
bazel-*
Expand Down
21 changes: 21 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,29 @@ load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files", "strip_prefix")
load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip")
load("//:protobuf_javascript_release.bzl", "package_naming")

config_setting(
name = "x64_x86_windows",
values = {"cpu": "x64_x86_windows"},
)

config_setting(
name = "x64_windows",
values = {"cpu": "x64_windows"},
)

config_setting(
name = "k8",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically not required for the windows build but it doesn't hurt anything so I left it here so you can strill build the linux-x86_64 build using --cpu k8

values = {"cpu": "k8"},
)

package_naming(
name = "protobuf_javascript_pkg_naming",
platform = select({
":k8": "linux-x86_64", # currently the only supported build type in Github Actions
":x64_x86_windows": "win32",
":x64_windows": "win64",
"//conditions:default": "" # continues with current behavior when no --cpu is specified allowing existing internal builds to function
})
)

pkg_files(
Expand Down
5 changes: 5 additions & 0 deletions protobuf_javascript_release.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def _package_naming_impl(ctx):
values = {}
values["version"] = _PROTOBUF_JAVASCRIPT_VERSION

if ctx.attr.platform != "":
values["platform"] = ctx.attr.platform
return PackageVariablesInfo(values=values)

# infer from the current cpp toolchain.
toolchain = find_cpp_toolchain(ctx)
cpu = toolchain.cpu
Expand Down Expand Up @@ -46,6 +50,7 @@ package_naming = rule(
"_cc_toolchain":
attr.label(
default=Label("@bazel_tools//tools/cpp:current_cc_toolchain"),),
"platform": attr.string(),
},
toolchains=["@bazel_tools//tools/cpp:toolchain_type"],
incompatible_use_toolchain_transition=True,
Expand Down