Skip to content

Commit

Permalink
simplify publish and release
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed Dec 11, 2021
1 parent 8ca30ec commit 764bec3
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 78 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,17 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: bazelbuild/setup-bazelisk@v1
- name: bazel test //...
env:
# Bazelisk will download bazel to here
XDG_CACHE_HOME: ~/.cache/bazel-repo
run: bazel --bazelrc=.github/workflows/ci.bazelrc --bazelrc=.bazelrc test //...
- name: Rename release artifact with version
run: cp $(ls bazel-out/*/bin/*.tar.gz | tail -1) "rules_swc-$(git describe --tags | sed 's/^v//').tar.gz"
# TODO: move this into bazel to produce the file with expand_template rule when it has stamping
- name: Prepare workspace snippet
run: |
echo -e "WORKSPACE snippet:\n\n\`\`\`starlark\nhttp_archive(\n name = \"aspect_rules_swc\"," > release_notes.txt
echo " sha256 = \"$(shasum -a 256 *.tar.gz | awk '{print $1}')\"," >> release_notes.txt
echo -e " url = \"https://github.com/myorg/rules_swc/releases/download/$(git describe --tags)/$(ls *.tar.gz)\",\n)\n\`\`\`" >> release_notes.txt
run: .github/workflows/workspace_snippet.sh ${{ env.GITHUB_REF_NAME }} > release_notes.txt
- name: Release
uses: softprops/action-gh-release@v1
with:
prerelease: true
# Use GH feature to populate the changelog automatically
generate_release_notes: true
body_path: release_notes.txt
files: "*.tar.gz"
52 changes: 52 additions & 0 deletions .github/workflows/workspace_snippet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail

# Set by GH actions, see
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
TAG=${GITHUB_REF_NAME}
PREFIX="rules_swc-${TAG:1}"
SHA=$(git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip | shasum -a 256 | awk '{print $1}')

cat << EOF
WORKSPACE snippet:
\`\`\`starlark
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "aspect_rules_swc",
sha256 = "${SHA}",
strip_prefix = "${PREFIX}",
url = "https://github.com/aspect-build/rules_swc/archive/${TAG}.tar.gz",
)
# Fetches the rules_swc dependencies.
# If you want to have a different version of some dependency,
# you should fetch it *before* calling this.
# Alternatively, you can skip calling this function, so long as you've
# already fetched all the dependencies.
load("@aspect_rules_swc//swc:dependencies.bzl", "rules_swc_dependencies")
rules_swc_dependencies()
# Fetches a pre-built Rust-node binding from
# https://github.com/swc-project/swc/releases.
# If you'd rather compile it from source, you can use rules_rust, fetch the project,
# then register the toolchain yourself. (Note, this is not yet documented)
load("@aspect_rules_swc//swc:repositories.bzl", "swc_register_toolchains")
swc_register_toolchains(
name = "swc",
swc_version = "v1.2.118",
)
# Fetches a NodeJS interpreter, needed to run the swc CLI.
# You can skip this if you already register a nodejs toolchain.
load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")
nodejs_register_toolchains(
name = "node16",
node_version = "16.9.0",
)
# Fetches the npm packages needed to run @swc/cli
load("@swc_cli//:repositories.bzl", _swc_cli_deps = "npm_repositories")
_swc_cli_deps()
\`\`\`
EOF
5 changes: 1 addition & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ This means that any usage of `@rules_swc` on your system will point to this fold

## Releasing

1. Make sure your git state is at the right place (something like `git fetch; git checkout origin/main`)
1. Determine the next release version, following semver (could automate in the future from changelog)
1. `git tag -a v1.2.3` (will open an editor to put release notes)
1. `git push --tags`
1. Push a tag to the repo, or create one on the GH UI
1. Watch the automation run on GitHub actions
1. Update the release page with auto-generated release notes
51 changes: 3 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,54 +42,9 @@ Add this to the `.bazelrc` in your project:
build --enable_runfiles
```

Next, include this in your WORKSPACE file:

```starlark
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# See the rules_swc releases page for an up-to-date snippet.
_RULES_SWC_VERSION="391c3748d48e964b9987e614028db9cb9cd35868"
http_archive(
name = "aspect_rules_swc",
url = "https://github.com/aspect-build/rules_swc/archive/%s.zip" % _RULES_SWC_VERSION,
strip_prefix = "rules_swc-" + _RULES_SWC_VERSION,
sha256 = "174494327d7e715a8d95755c89afa71dd671d9f2d8296f96c772151a02036919",
)

# Fetches the rules_swc dependencies.
# If you want to have a different version of some dependency,
# you should fetch it *before* calling this.
# Alternatively, you can skip calling this function, so long as you've
# already fetched all the dependencies.
load("@aspect_rules_swc//swc:dependencies.bzl", "rules_swc_dependencies")
rules_swc_dependencies()

# Fetches a pre-built Rust-node binding from
# https://github.com/swc-project/swc/releases.
# If you'd rather compile it from source, you can use rules_rust, fetch the project,
# then register the toolchain yourself. (Note, this is not yet documented)
load("@aspect_rules_swc//swc:repositories.bzl", "swc_register_toolchains")
swc_register_toolchains(
name = "swc",
swc_version = "v1.2.118",
)

# Fetches a NodeJS interpreter, needed to run the swc CLI.
# You can skip this if you already register a nodejs toolchain.
load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")
nodejs_register_toolchains(
name = "node16",
node_version = "16.9.0",
)

# Fetches the npm packages needed to run @swc/cli
load("@swc_cli//:repositories.bzl", _swc_cli_deps = "npm_repositories")
_swc_cli_deps()
```

> note, in the above, replace the version and sha256 with the one indicated
> in the release notes for rules_swc
> In the future, our release automation should take care of this.
From the release you wish to use:
<https://github.com/aspect-build/rules_swc/releases>
copy the WORKSPACE snippet into your `WORKSPACE` file.

## Usage

Expand Down
10 changes: 0 additions & 10 deletions internal_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def rules_swc_internal_deps():
"Fetch deps needed for local development"
maybe(
http_archive,
name = "rules_pkg",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.2.4/rules_pkg-0.2.4.tar.gz",
],
sha256 = "4ba8f4ab0ff85f2484287ab06c0d871dcb31cc54d439457d28fd4ae14b18450a",
)

maybe(
http_archive,
name = "build_bazel_integration_testing",
Expand Down
15 changes: 8 additions & 7 deletions swc/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@ def rules_swc_dependencies():
maybe(
http_archive,
name = "rules_nodejs",
sha256 = "a2b1b60c51b0193ed1646accf77a28cfd4f4ce1f6c86f32ce11455101be3a9c4",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/4.4.3/rules_nodejs-core-4.4.3.tar.gz"],
sha256 = "8f4a19de1eb16b57ac03a8e9b78344b44473e0e06b0510cec14a81f6adfdfc25",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/4.4.6/rules_nodejs-core-4.4.6.tar.gz"],
)

maybe(
http_archive,
name = "aspect_bazel_lib",
sha256 = "7cb2faf813bae1712dcb09b23dd8d68fffd8631a25d54b9ca8ae866ca7debc06",
urls = ["https://github.com/aspect-build/bazel-lib/releases/download/v0.2.1/bazel_lib-0.2.1.tar.gz"],
sha256 = "e834c368f36cb336b5b42cd1dd9cd4b6bafa0ad3ed7f92f54a47e5ab436e4f59",
strip_prefix = "bazel-lib-0.3.0",
url = "https://github.com/aspect-build/bazel-lib/archive/v0.3.0.tar.gz",
)

maybe(
http_archive,
name = "aspect_rules_js",
sha256 = "eca89b1f6f7bbe96ebe16d949c260abaac660ed2d93bbed9c612abfe36344a2e",
strip_prefix = "rules_js-4420d070f3c696166384535e3cf4235434e85e8d",
url = "https://github.com/aspect-build/rules_js/archive/4420d070f3c696166384535e3cf4235434e85e8d.zip",
sha256 = "e8576a74a7e80b873179514cf1ad48b62b18ae024e74200ecd40ae6dc00c515a",
strip_prefix = "rules_js-0.3.0",
url = "https://github.com/aspect-build/rules_js/archive/v0.3.0.tar.gz",
)

0 comments on commit 764bec3

Please sign in to comment.