Skip to content

Commit

Permalink
Merge branch 'main' into xlr-entries
Browse files Browse the repository at this point in the history
  • Loading branch information
adierkens authored Aug 5, 2024
2 parents 1226bab + affc386 commit 6793960
Show file tree
Hide file tree
Showing 19 changed files with 24,700 additions and 638 deletions.
5 changes: 4 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
version: 2.1

orbs:
node: circleci/node@5.2.0

executors:
base:
docker:
- image: docker.io/sugarmanz/bazel-common
- image: docker.io/playerui/bazel-docker
working_directory: ~/rules_player
resource_class: large
environment:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
/.settings
/.vscode/
/bazel.iml

# Ignore generated file from gh-page.
/gh-pages/private/gh-pages.js

# Ignore all bazel-* symlinks. There is no full list since this can change
# based on the name of the directory bazel is cloned into.
**/bazel-*
Expand Down
61 changes: 61 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
# v1.1.3 (Sun Aug 04 2024)

#### 🐛 Bug Fix

- Stamping Fix - Calls the right stamp file [#71](https://github.com/player-ui/rules_player/pull/71) ([@mercillo](https://github.com/mercillo))

#### Authors: 1

- Marlon "Marky" Ercillo ([@mercillo](https://github.com/mercillo))

---

# v1.1.2 (Sat Aug 03 2024)

#### 🐛 Bug Fix

- Fix stamp_tar_files [#70](https://github.com/player-ui/rules_player/pull/70) ([@mercillo](https://github.com/mercillo))

#### Authors: 1

- Marlon "Marky" Ercillo ([@mercillo](https://github.com/mercillo))

---

# v1.1.1 (Fri Aug 02 2024)

#### 🐛 Bug Fix

- Removing generation of js file [#69](https://github.com/player-ui/rules_player/pull/69) ([@mercillo](https://github.com/mercillo))
- Add GH script [#67](https://github.com/player-ui/rules_player/pull/67) ([@mercillo](https://github.com/mercillo))

#### Authors: 1

- Marlon "Marky" Ercillo ([@mercillo](https://github.com/mercillo))

---

# v1.1.0 (Thu Aug 01 2024)

#### 🚀 Enhancement

- Bazel6 - stamping tars, generating gh-page.js, and deploying gh-pages [#62](https://github.com/player-ui/rules_player/pull/62) ([@mercillo](https://github.com/mercillo))

#### 🐛 Bug Fix

- Gitignore update [#65](https://github.com/player-ui/rules_player/pull/65) ([@mercillo](https://github.com/mercillo))
- Gitignore - ghpage.js update [#64](https://github.com/player-ui/rules_player/pull/64) ([@mercillo](https://github.com/mercillo))

#### 🏠 Internal

- Lint & Fix all *.bzl files [#60](https://github.com/player-ui/rules_player/pull/60) ([@adierkens](https://github.com/adierkens))
- Update examples to use rules_bazel_integration_test [#59](https://github.com/player-ui/rules_player/pull/59) ([@adierkens](https://github.com/adierkens))
- Generate docs for all rules [#58](https://github.com/player-ui/rules_player/pull/58) ([@adierkens](https://github.com/adierkens))

#### Authors: 2

- Adam Dierkens ([@adierkens](https://github.com/adierkens))
- Marlon "Marky" Ercillo ([@mercillo](https://github.com/mercillo))

---

# v1.0.1 (Thu Jul 18 2024)

#### 🐛 Bug Fix
Expand Down
8 changes: 4 additions & 4 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module(
)

bazel_dep(name = "cgrindel_bazel_starlib", version = "0.21.0")
bazel_dep(name = "aspect_bazel_lib", version = "1.32.0")
bazel_dep(name = "aspect_rules_js", version = "1.33.1")
bazel_dep(name = "aspect_bazel_lib", version = "1.38.1")
bazel_dep(name = "aspect_rules_js", version = "1.34.0")
bazel_dep(name = "aspect_rules_rollup", version = "1.0.0")
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "bazel_skylib", version = "1.4.2")
bazel_dep(name = "rules_pkg", version = "0.9.1")
bazel_dep(name = "aspect_rules_ts", version = "2.1.0")
bazel_dep(name = "platforms", version = "0.0.5")
bazel_dep(name = "platforms", version = "0.0.9")

rules_ts_ext = use_extension(
"@aspect_rules_ts//ts:extensions.bzl",
Expand Down
15 changes: 15 additions & 0 deletions distribution/tar/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_missing_pkgs", "bzlformat_pkg")

bzlformat_pkg(name = "bzlformat")

bzlformat_missing_pkgs(name = "bzlformat_missing_pkgs")

bzl_library(
name = "defs",
srcs = ["defs.bzl"],
visibility = ["//visibility:public"],
deps = [],
)

exports_files(["defs.bzl"])
7 changes: 7 additions & 0 deletions distribution/tar/defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Public API for JavaScript based project rules
"""

load("//distribution/tar/private:stamp_tar_files.bzl", _stamp_tar_files = "stamp_tar_files")

stamp_tar_files = _stamp_tar_files
21 changes: 21 additions & 0 deletions distribution/tar/private/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@aspect_rules_js//js:defs.bzl", "js_binary")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_missing_pkgs", "bzlformat_pkg")

bzlformat_pkg(name = "bzlformat")

bzlformat_missing_pkgs(name = "bzlformat_missing_pkgs")

bzl_library(
name = "stamp_tar_files",
srcs = ["stamp_tar_files.bzl"],
visibility = [
"//distribution:__subpackages__",
],
)

js_binary(
name = "stamp_tar_files_script",
entry_point = "stamp_tar_files.mjs",
visibility = ["//visibility:public"],
)
81 changes: 81 additions & 0 deletions distribution/tar/private/stamp_tar_files.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""
Module for stamping a tar.gz file and repackaging it
"""

load("@aspect_bazel_lib//lib:stamping.bzl", "STAMP_ATTRS", "maybe_stamp")
load("@bazel_skylib//lib:paths.bzl", "paths")

_STAMP_TAR_FILES = Label("//distribution/tar/private:stamp_tar_files_script")

def stamp_tar_impl(ctx):
"""
this takes a tar file, calls maybe_stamp and replaces any variables in that file with the substituions passed, and then repackages the entire tar.
Args:
ctx: tar, substitutions
maybe_stamp() generates a stable and volatile file in bazel-out
Returns:
stamped tar file
"""

inputs = []

stamped_tar = ctx.actions.declare_file(paths.basename(ctx.attr.name + ".tar.gz"))

stamp = maybe_stamp(ctx)

args = {
"input_file": ctx.file.tar.short_path,
"output_file": stamped_tar.short_path,
"stable": ctx.attr.stable,
"stamp": ctx.info_file.path if stamp else None,
"substitutions": ctx.attr.substitutions,
}

if stamp:
inputs = [stamp.volatile_status_file, stamp.stable_status_file]
args["stable_file"] = stamp.stable_status_file.path
args["volatile_file"] = stamp.volatile_status_file.path

ctx.actions.run(
inputs = inputs + ctx.files.tar,
outputs = [stamped_tar],
arguments = [json.encode(args)],
executable = ctx.executable._stamp_tar_files_exec,
mnemonic = "tar",
env = {
"BAZEL_BINDIR": ctx.bin_dir.path,
},
)

return [
DefaultInfo(
files = depset([stamped_tar]),
),
]

stamp_tar_files = rule(
implementation = stamp_tar_impl,
attrs = dict({
"stable": attr.bool(
default = False,
doc = "If true, replaces variables from stable-status. False replaces from volatile-status",
),
"substitutions": attr.string_dict(
doc = "A mapping of values to replace in a file, to the stamp variables",
),
"tar": attr.label(
allow_single_file = True,
mandatory = True,
doc = "The files to stamp",
),
"_stamp_tar_files_exec": attr.label(
default = _STAMP_TAR_FILES,
executable = True,
doc = "The executable to run the stamping",
cfg = "exec",
),
}, **STAMP_ATTRS),
)
96 changes: 96 additions & 0 deletions distribution/tar/private/stamp_tar_files.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
import {spawnSync} from 'child_process';
import process from 'process';


async function handleSubstitutions(folderOrFile, substitutions) {
if (Object.keys(substitutions).length === 0) {
return;
}

if ((await fs.promises.stat(folderOrFile)).isDirectory()) {
const files = await fs.promises.readdir(folderOrFile);
for (const file of files) {
await handleSubstitutions(path.join(folderOrFile, file), substitutions);
}

return;
}

let contents = await fs.promises.readFile(folderOrFile, "utf-8");

const originalContents = contents;
for (const key in substitutions) {
const value = substitutions[key];
contents = contents.replace(new RegExp(key, "g"), value);
}

if (contents !== originalContents) {
await fs.promises.writeFile(folderOrFile, contents);
}

}

const repackageTar = async (input_file, output_file, substitutions) => {
const tempDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'stamping-'))
const tempOutputDir = path.join(tempDir, "output");
await fs.promises.mkdir(tempOutputDir, { recursive: true });

spawnSync('tar',['-xzvf', input_file, '-C', tempOutputDir], {stdio:'inherit'})

await handleSubstitutions(tempOutputDir, substitutions);


spawnSync('tar',['-czvf', output_file, '-C', tempOutputDir, '.'], {stdio:'inherit'})
}


const main = async ([config]) => {
const { input_file, output_file,stable, stamp, substitutions,volatile_file, stable_file} = JSON.parse(config);

const resolvedInputFile = path.resolve(input_file)
const resolvedOutputFile = path.resolve(output_file)

// If stamping doesnt exist, just copy files
if (!stamp) {
fs.copyFileSync(resolvedInputFile, resolvedOutputFile);
return;
}

let file = stable ? stable_file : volatile_file

// need this to find the bazel-out/ path
process.chdir(process.env.JS_BINARY__EXECROOT)

const stampFile = fs.readFileSync(file,"utf-8");

// TODO: Should share this as a common module
stampFile.split("\n").forEach((line) => {
const firstSpace = line.indexOf(" ");
const varName = line.substring(0, firstSpace);
let varVal = line.substring(firstSpace + 1);

// Using the same match as https://github.com/bazelbuild/rules_nodejs/blob/stable/internal/pkg_npm/packager.js#L139
if (varName.endsWith('_VERSION')) {
// vscode doesn't let you have `-canary` suffixes
varVal = varVal.replace(/[^\d.]/g, '');
}

// Swap out anything referencing the stamped file with the actual value
Object.keys(substitutions).forEach((key) => {
if (substitutions[key] === `{${varName}}`) {
substitutions[key] = varVal;
}
});
});

await repackageTar(resolvedInputFile, resolvedOutputFile, substitutions);

};

main(process.argv.slice(2)).catch((e) => {
console.error(e);
process.exit(1);
})
15 changes: 15 additions & 0 deletions gh-pages/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_missing_pkgs", "bzlformat_pkg")

bzlformat_pkg(name = "bzlformat")

bzlformat_missing_pkgs(name = "bzlformat_missing_pkgs")

exports_files(["defs.bzl"])

bzl_library(
name = "defs",
srcs = ["defs.bzl"],
visibility = ["//visibility:public"],
deps = [],
)
7 changes: 7 additions & 0 deletions gh-pages/defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Public API for JavaScript based project rules
"""

load("//gh-pages/private:gh-deploy.bzl", _gh_pages = "gh_pages")

gh_pages = _gh_pages
31 changes: 31 additions & 0 deletions gh-pages/private/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@aspect_rules_js//js:defs.bzl", "js_binary","js_run_binary","js_library")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

package(default_visibility = ["//visibility:public"])

js_library(
name = "gh_pages_lib",
srcs = [
"gh-pages.js"
],
visibility = ["//visibility:public"],
)
exports_files([
"gh-pages.js"
])

js_binary(
name = "gh_pages_bin",
data = ["//gh-pages/private:gh-pages.js"],
entry_point = "//gh-pages/private:gh-pages.js",
visibility = ["//visibility:public"],

)

filegroup(
name = "npm_depdencies",
srcs = glob(["node_modules/**/*"]),
visibility = [
"//visibility:public"
]
)
Loading

0 comments on commit 6793960

Please sign in to comment.