Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
kormide committed Mar 21, 2022
1 parent bda5c63 commit 5d741ee
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .bcr/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"aspect-build/bazel-lib"

module(
name = "aspect_bazel_lib",
version = "VERSION_PLACEHOLDER",
compatibility_level = 1,
)

bazel_dep(name = "bazel_skylib", version = "1.0.3")
12 changes: 12 additions & 0 deletions .bcr/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"homepage": "https://docs.aspect.dev/bazel-lib",
"maintainers": [
{
"email": "[email protected]",
"github": "aspect-build",
"name": "Aspect team"
}
],
"versions": [],
"yanked_versions": {}
}
14 changes: 14 additions & 0 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
build_targets: &build_targets
- "@aspect_bazel_lib//lib/tests:expand_template_test"

platforms:
centos7:
build_targets: *build_targets
debian10:
build_targets: *build_targets
macos:
build_targets: *build_targets
ubuntu2004:
build_targets: *build_targets
windows:
build_targets: *build_targets
5 changes: 5 additions & 0 deletions .bcr/source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"integrity": "SHA256_PLACEHOLDER",
"strip_prefix": "bazel-lib-VERSION_PLACEHOLDER",
"url": "https://github.com/aspect-build/bazel-lib/archive/vVERSION_PLACEHOLDER.tar.gz"
}
39 changes: 39 additions & 0 deletions .github/workflows/bcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Create a pull request to update the bazel central registry
# when a new release has been cut.
name: BCR

on:
release:
types: [published]

jobs:
pull-request:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v2
with:
node-version: "14"
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
- run: pwd
- run: ls
- name: Checkout the released version of this repo
uses: actions/checkout@v2
with:
ref: ${{ env.GITHUB_REF }}
path: ${{ env.GITHUB_REPOSITORY }}
- run: pwd
- name: Checkout bcr
uses: actions/checkout@v3
with:
#TODO: change to bazelbuild
repository: kormide/bazel-central-registry
path: bcr
- run: pwd
- name: Create a new bcr branch
working-directory: bcr
run: git checkout -b "$GITHUB_REPOSITORY@${{ steps.get_version.outputs.VERSION }}"
- run: pwd
- name: Create the bcr entry
run: node .github/workflows/create-bcr-entry.js $GITHUB_REPOSITORY bcr ${{ steps.get_version.outputs.VERSION }}
92 changes: 92 additions & 0 deletions .github/workflows/create-bcr-entry.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import {
readFileSync,
mkdirSync,
existsSync,
copyFileSync,
writeFileSync,
} from "fs";
import { resolve } from "path";

/**
* Create a bcr entry for a new version of this repository. Assumes the
* project and bcr repositories are checked out locally. After running,
* the local bcr changes should be committed and PR'ed.
*
* Usage: create-bcr-entry [project_path] [bcr_path] [version]
*
* project_path: path to the project's repository; should contain a
* .bcr folder with MODULE.bazel and templated bcr entry files.
* bcr_path: path to the bcr repository
* version: new version of the project
*
*/
function main(argv) {
if (process.argv.length !== 3) {
console.error(
"usage: create-bcr-entry [project_path] [bcr_path] [version]"
);
process.exit(1);
}

console.log(`${argv[0]} ${argv[1]} ${argv[2]}`);

const projectPath = argv[0];
const modulePath = resolve(projectPath, ".bcr", "MODULE.bazel");
const sourcePath = resolve(projectPath, ".bcr", "source.json");
const bcrPath = argv[1];
const version = normalizeVersion(argv[2]);
const moduleContent = readFileSync(modulePath, { encoding: "utf-8" });
const moduleName = getModuleName(moduleContent);
const bcrEntryPath = resolve(bcrPath, "modules", moduleName);
const bcrVersionEntryPath = resolve(bcrEntryPath, version);

mkdirSync(bcrVersionEntryPath);

// Create a metadata.json file if one doesn't exist
const metadataPath = resolve(bcrEntryPath, "metadata.json");
if (!existsSync(metadataPath)) {
copyFileSync(
resolve(projectPath, ".bcr", "metadata.json"),
resolve(bcrEntryPath, "metadata.json")
);
}

// Add new version to metadata.json
const metadata = require(metadataPath);
metadata.versions.push(version);
writeFileSync(metadataPath, JSON.stringify(metadata, null, 4));

// Substitute version into MODULE.bazel
moduleContent = moduleContent.replace("VERSION_PLACEHOLDER", version);
writeFileSync(resolve(bcrVersionEntryPath, "MODULE.bazel"), moduleContent, {
encoding: "utf-8",
});

// TODO: Set compat basaed on major version difference

// Substitute version and integrity hash into source.json
const sourceContent = readFileSync(sourcePath, { encoding: "utf-8" });
sourceContent = sourceContent
.replace("VERSION_PLACEHOLDER", version)
.replace("SHA256_PLACEHOLDER", "");
}

function getModuleName(moduleContent) {
const regex = /module\(.*?name\s*=\s*"(\w+)"/s;
const match = moduleContent.match(regex);
if (match) {
return match[1];
}
throw new Error("Could not parse module name from module file");
}

function normalizeVersion(version) {
if (version.startsWith("v")) {
return version.substring(1);
}
}

if (require.main === module) {
const argv = process.argv.slice(2);
main(argv);
}

0 comments on commit 5d741ee

Please sign in to comment.