Skip to content
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

Fix #2: Introduce GitHub Actions #6

Open
wants to merge 8 commits into
base: introduce-proto-api-v1
Choose a base branch
from
Open
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
37 changes: 37 additions & 0 deletions .github/workflows/bazel_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Contains job corresponding to bazel build.

name: Bazel Build

on:
workflow_dispatch:
pull_request:
push:
branches:
# Push events on develop branch
- develop

jobs:
bazel_build_app:
name: Build Binary with Bazel
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up JDK 9
uses: actions/setup-java@v1
with:
java-version: 9

- name: Set up Bazel
uses: abhinavsingh/setup-bazel@v3
with:
version: 4.2.0

- name: Build Oppia Proto API
run: |
bazel build -- //:android_protos
Copy link
Member

Choose a reason for hiding this comment

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

I suggest instead building //... (to make sure everything builds).

37 changes: 37 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Contains job corresponding to lint check of Bazel files.

name: Lint check

on:
workflow_dispatch:
pull_request:
push:
branches:
# Push events on develop branch
- develop

jobs:
lint_check:
name: Lint check
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up JDK 9
uses: actions/setup-java@v1
with:
java-version: 9

- name: Set up Bazel
uses: abhinavsingh/setup-bazel@v3
with:
version: 4.2.0

- name: Lint check using Buildifier
run: |
bazel run -- //:buildifier
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel-*
11 changes: 8 additions & 3 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ public, importable API should be defined here (and all such libraries should be
nowhere else).
"""

load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_java//java:defs.bzl", "java_lite_proto_library", "java_proto_library")

buildifier(
name = "buildifier",
)

package_group(
name = "api_visibility",
packages = [
Expand All @@ -30,9 +35,9 @@ proto_library(
name = "android_protos",
visibility = ["//visibility:public"],
deps = [
"//proto/v1/api:android_proto",
"//proto/v1/structure:structure_proto",
"//proto/v1/versions:versions_proto",
"//proto/v1/api:android_proto",
"//proto/v1/structure:structure_proto",
"//proto/v1/versions:versions_proto",
],
)

Expand Down
12 changes: 12 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ load("//repo:deps.bzl", "initializeDepsForWorkspace")

initializeDepsForWorkspace()

load("//repo:deps.bzl", "initializeGoDeps")
initializeGoDeps()

load("//repo:deps.bzl", "initializeBazelGazell")
initializeBazelGazell()

load("//repo:deps.bzl", "initializeProtobuf")
initializeProtobuf()

load("//repo:deps.bzl", "initializeBazelBuildTools")
initializeBazelBuildTools()

Comment on lines +9 to +20
Copy link
Author

Choose a reason for hiding this comment

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

Throwing error when running bazel run //:buildifier

ERROR: Failed to load Starlark extension '@bazel_gazelle//:deps.bzl'.
Cycle in the workspace file detected. This indicates that a repository is used prior to being defined.
The following chain of repository dependencies lead to the missing definition.
 - @bazel_gazelle
This could either mean you have to add the '@bazel_gazelle' repository with a statement like `http_archive` in your WORKSPACE file (note that transitive dependencies are not added automatically), or move an existing definition earlier in your WORKSPACE file.
ERROR: cycles detected during target parsing
INFO: Elapsed time: 0.100s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
FAILED: Build did NOT complete successfully (0 packages loaded)

load("//repo:toolchains.bzl", "initializeToolchainsForWorkspace")

initializeToolchainsForWorkspace()
8 changes: 4 additions & 4 deletions proto/v1/api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ load("@rules_proto//proto:defs.bzl", "proto_library")
proto_library(
name = "android_proto",
srcs = ["android.proto"],
visibility = ["//:api_visibility"],
strip_import_prefix = "", # Strip the default file prefix so that it may be redefined.
import_prefix = "org/oppia/proto/v1/api", # Make directory prefix match declared package.
strip_import_prefix = "", # Strip the default file prefix so that it may be redefined.
visibility = ["//:api_visibility"],
deps = [
"//proto/v1/structure:structure_proto",
"//proto/v1/versions:versions_proto",
"//proto/v1/structure:structure_proto",
"//proto/v1/versions:versions_proto",
],
)
4 changes: 2 additions & 2 deletions proto/v1/structure/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ proto_library(
"state.proto",
"topic_summary.proto",
],
strip_import_prefix = "", # Strip the default file prefix so that it may be redefined.
import_prefix = "org/oppia/proto/v1/structure", # Make directory prefix match declared package.
strip_import_prefix = "", # Strip the default file prefix so that it may be redefined.
visibility = [
"//:api_visibility",
"//:proto_impl_visibility",
],
deps = [
"//proto/v1/versions:versions_proto",
"//proto/v1/versions:versions_proto",
],
)
4 changes: 2 additions & 2 deletions proto/v1/versions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ proto_library(
"api_versions.proto",
"structure_versions.proto",
],
strip_import_prefix = "", # Strip the default file prefix so that it may be redefined.
import_prefix = "org/oppia/proto/v1/versions", # Make directory prefix match declared package.
strip_import_prefix = "", # Strip the default file prefix so that it may be redefined.
visibility = [
"//:api_visibility",
"//:proto_impl_visibility",
],
deps = [
"@com_google_protobuf//:descriptor_proto",
"@com_google_protobuf//:descriptor_proto",
],
)
156 changes: 100 additions & 56 deletions repo/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,83 +5,127 @@ instructions in the README for more details.
"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

# Note to developers: Please keep this dict sorted by key to make it easier to find dependencies.
_DEPENDENCY_VERSIONS = {
"rules_python": {
"sha": "934c9ceb552e84577b0faf1e5a2f0450314985b4d8712b2b70717dc679fdc01b",
"url": "https://github.com/bazelbuild/rules_python/releases/download/{0}/rules_python-{0}.tar.gz",
"version": "0.3.0",
},
"com_google_protobuf": {
"sha": "c6003e1d2e7fefa78a3039f19f383b4f3a61e81be8c19356f85b6461998ad3db",
"strip_prefix": "protobuf-{0}",
"url": "https://github.com/protocolbuffers/protobuf/archive/v{0}.tar.gz",
"version": "3.17.3",
},
"rules_proto": {
# Note that rules_proto doesn't have any shipped versions, so the workspace needs to pin to a
# specific commit hash.
"sha": "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
"strip_prefix": "rules_proto-{0}",
"url": "https://github.com/bazelbuild/rules_proto/archive/{0}.tar.gz",
"version": "97d8af4dc474595af3900dd85cb3a29ad28cc313",
},
"rules_java": {
"sha": "220b87d8cfabd22d1c6d8e3cdb4249abd4c93dcc152e0667db061fb1b957ee68",
"url": "https://github.com/bazelbuild/rules_java/releases/download/{0}/rules_java-{0}.tar.gz",
"version": "0.1.1",
},
"rules_python": {
"sha": "934c9ceb552e84577b0faf1e5a2f0450314985b4d8712b2b70717dc679fdc01b",
"url": "https://github.com/bazelbuild/rules_python/releases/download/{0}/rules_python-{0}.tar.gz",
"version": "0.3.0",
},
"com_google_protobuf": {
"sha": "c6003e1d2e7fefa78a3039f19f383b4f3a61e81be8c19356f85b6461998ad3db",
"strip_prefix": "protobuf-{0}",
"url": "https://github.com/protocolbuffers/protobuf/archive/v{0}.tar.gz",
"version": "3.17.3",
},
"rules_proto": {
# Note that rules_proto doesn't have any shipped versions, so the workspace needs to pin to a
# specific commit hash.
"sha": "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
"strip_prefix": "rules_proto-{0}",
"url": "https://github.com/bazelbuild/rules_proto/archive/{0}.tar.gz",
"version": "97d8af4dc474595af3900dd85cb3a29ad28cc313",
},
"rules_java": {
"sha": "220b87d8cfabd22d1c6d8e3cdb4249abd4c93dcc152e0667db061fb1b957ee68",
"url": "https://github.com/bazelbuild/rules_java/releases/download/{0}/rules_java-{0}.tar.gz",
"version": "0.1.1",
},
"io_bazel_rules_go": {
"sha": "2b1641428dff9018f9e85c0384f03ec6c10660d935b750e3fa1492a281a53b0f",
"url": "https://github.com/bazelbuild/rules_go/releases/download/{0}/rules_go-{0}.zip",
"version": "v0.29.0",
},
"bazel_gazelle": {
"sha": "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb",
"url": "https://github.com/bazelbuild/bazel-gazelle/releases/download/{0}/bazel-gazelle-{0}.tar.gz",
"version": "v0.24.0",
},
"com_github_bazelbuild_buildtools": {
"sha": "ae34c344514e08c23e90da0e2d6cb700fcd28e80c02e23e4d5715dddcb42f7b3",
"strip_prefix": "buildtools-{0}",
"url": "https://github.com/bazelbuild/buildtools/archive/refs/tags/{0}.tar.gz",
"version": "4.2.2",
},
}

def _setUpHttpArchiveDependency(name):
metadata = _DEPENDENCY_VERSIONS[name]
sha = metadata["sha"]
strip_prefix = metadata.get("strip_prefix")
url = metadata["url"]
version = metadata["version"]
metadata = _DEPENDENCY_VERSIONS[name]
sha = metadata["sha"]
strip_prefix = metadata.get("strip_prefix")
url = metadata["url"]
version = metadata["version"]

formatted_strip_prefix = strip_prefix.format(version) if not (strip_prefix == None) else None
formatted_strip_prefix = strip_prefix.format(version) if not (strip_prefix == None) else None

http_archive(
name = name,
urls = [url.format(version)],
sha256 = sha,
strip_prefix = formatted_strip_prefix,
)
http_archive(
name = name,
urls = [url.format(version)],
sha256 = sha,
strip_prefix = formatted_strip_prefix,
)

def _setUpPython():
_setUpHttpArchiveDependency(name = "rules_python")
_setUpHttpArchiveDependency(name = "rules_python")

def _setUpProtobuf():
_setUpHttpArchiveDependency(name = "com_google_protobuf")
_setUpHttpArchiveDependency(name = "com_google_protobuf")

def _setUpRulesProto():
_setUpHttpArchiveDependency(name = "rules_proto")
_setUpHttpArchiveDependency(name = "rules_proto")

def _setUpRulesJava():
_setUpHttpArchiveDependency(name = "rules_java")
_setUpHttpArchiveDependency(name = "rules_java")

def _setUpIoBazelRulesGo():
_setUpHttpArchiveDependency(name ="io_bazel_rules_go")

def _setUpBazelGazell():
_setUpHttpArchiveDependency(name ="bazel_gazelle")

def _setUpBazelBuildTools():
_setUpHttpArchiveDependency(name ="com_github_bazelbuild_buildtools")

def initializeDepsForWorkspace():
"""
Loads the dependencies needed to be able to build the Oppia proto API project.
"""
Loads the dependencies needed to be able to build the Oppia proto API project.

Note that this must be called after loading in this deps file, for example:

load("//repo:deps.bzl", "initializeDepsForWorkspace")
initializeDepsForWorkspace()

Note also that toolchains may need to be set up after loading this dependencies (see
toolchains.bzl).
"""

# Set up Python (as a prerequisite dependency for Protobuf).
_setUpPython()

_setUpProtobuf()

# Set up rules_proto to allow defining proto libraries.
_setUpRulesProto()

Note that this must be called after loading in this deps file, for example:
# Set up rules_java to enable the Java proto & Java proto lite rules.
_setUpRulesJava()

load("//repo:deps.bzl", "initializeDepsForWorkspace")
initializeDepsForWorkspace()
_setUpIoBazelRulesGo()

Note also that toolchains may need to be set up after loading this dependencies (see
toolchains.bzl).
"""
# Set up Python (as a prerequisite dependency for Protobuf).
_setUpPython()
def initializeGoDeps():
go_rules_dependencies()
go_register_toolchains(version = "1.17.2")

# Set up proto & its toolchain.
_setUpProtobuf()
def initializeBazelGazell():
_setUpBazelGazell()
gazelle_dependencies()

# Set up rules_proto to allow defining proto libraries.
_setUpRulesProto()
def initializeProtobuf():
protobuf_deps()

# Set up rules_java to enable the Java proto & Java proto lite rules.
_setUpRulesJava()
def initializeBazelBuildTools():
_setUpBazelBuildTools()
27 changes: 14 additions & 13 deletions repo/toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_
load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")

def initializeToolchainsForWorkspace():
"""
Initializes the toolchains needed to be able to build the Oppia proto API project.
"""
Initializes the toolchains needed to be able to build the Oppia proto API project.

Note that this must be called after loading in this toolchains file, for example:
Note that this must be called after loading in this toolchains file, for example:

load("//repo:toolchains.bzl", "initializeToolchainsForWorkspace")
initializeToolchainsForWorkspace()
load("//repo:toolchains.bzl", "initializeToolchainsForWorkspace")
initializeToolchainsForWorkspace()

Note also that this can't be called until the dependencies themselves are loaded (see deps.bzl).
"""
# Set up the toolchains for rules_proto.
rules_proto_dependencies()
rules_proto_toolchains()
Note also that this can't be called until the dependencies themselves are loaded (see deps.bzl).
"""

# Set up the toolchains for rules_java.
rules_java_dependencies()
rules_java_toolchains()
# Set up the toolchains for rules_proto.
rules_proto_dependencies()
rules_proto_toolchains()

# Set up the toolchains for rules_java.
rules_java_dependencies()
rules_java_toolchains()