Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelnaranjo committed Jul 15, 2024
1 parent 650f881 commit 0916a06
Show file tree
Hide file tree
Showing 29 changed files with 290 additions and 251 deletions.
5 changes: 1 addition & 4 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import %workspace%/.aspect/bazelrc/performance.bazelrc
# Specific project flags go here if we have some
common --incompatible_enable_proto_toolchain_resolution

# register toolchains with prebuilts
common:prebuilt-toolchain --extra_toolchains=@bazeldnf_toolchains//:all

common:built-toolchain --extra_toolchains=//cmd:bazeldnf-host-toolchain
common --extra_toolchains=//cmd:bazeldnf-host-toolchain

common --enable_bzlmod

Expand Down
10 changes: 3 additions & 7 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ docs/*.md linguist-generated=true

# Configuration for 'git archive'
# see https://git-scm.com/docs/git-archive/2.40.0#ATTRIBUTES
# Exclude a bungh of paths to save some disk space
# Exclude a bunch of paths to save some disk space
e2e export-ignore
.aspect export-ignore
.github export-ignore
hack export-ignore

# Substitution for the _VERSION_PRIVATE placeholder
tools/version.bzl export-subst
.aspect
.github
1 change: 0 additions & 1 deletion .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
repository-cache: true
bazelrc: |
import %workspace%/.github/workflows/ci.bazelrc
common --config=built-toolchain
- run: bazel build //... && bazel test //...

Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/build_assets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail
set -x

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

${SCRIPT_DIR}/generate_tools_versions.sh

bazel run //tools/release
16 changes: 16 additions & 0 deletions .github/workflows/generate_tools_versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail
set -x

# Set by GH actions, see
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
REPO_URL="${GITHUB_REPOSITORY:-rmohr/bazeldnf}"
OUT=${PREFIX:-.}/tools/version.bzl
cat > ${OUT} <<EOF
"Generated during release generate_tools_prebuilts.sh"
VERSION = "${GITHUB_REF_NAME}"
REPO_URL = "${REPO_URL}"
EOF
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ jobs:


- name: Build Binaries
run: bazel run //tools/release

run: .github/workflows/build_assets.sh
- uses: actions/upload-artifact@v4
with:
name: artifacts
Expand Down
39 changes: 23 additions & 16 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail
set -x

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# Set by GH actions, see
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
TAG=${GITHUB_REF_NAME}

# The prefix is chosen to match what GitHub generates for source archives
PREFIX="bazeldnf-${TAG:1}"
ARCHIVE="bazeldnf-$TAG.tar.gz"
PREFIX="bazeldnf-${GITHUB_REF_NAME}"
ARCHIVE="bazeldnf-${GITHUB_REF_NAME}.tar.gz"
ARCHIVE_TMP=$(mktemp)

REPO_URL="${GITHUB_REPOSITORY:-rmohr/bazeldnf}"

# NB: configuration for 'git archive' is in /.gitattributes
git archive --format=tar --prefix=${PREFIX}/ --worktree-attributes ${TAG} > $ARCHIVE_TMP
git archive --format=tar --prefix=${PREFIX}/ --worktree-attributes ${GITHUB_REF_NAME} > $ARCHIVE_TMP

############
# Patch up the archive to have integrity hashes for built binaries that we downloaded in the GHA workflow.
# Now that we've run `git archive` we are free to pollute the working directory.

# Delete the placeholder file
tar --file $ARCHIVE_TMP --delete ${PREFIX}/bazeldnf/private/prebuilts.bzl
# Delete the placeholder files
tar --file $ARCHIVE_TMP --delete ${PREFIX}/tools/version.bzl
tar --file $ARCHIVE_TMP --delete ${PREFIX}/tools/integrity.bzl

# Add trailing newlines to sha256 files. They were built with
# https://github.com/aspect-build/bazel-lib/blob/main/tools/release/hashes.bzl
Expand All @@ -29,36 +31,41 @@ for sha in $(ls artifacts/*.sha256); do
done

mkdir -p ${PREFIX}/tools
cat >${PREFIX}/tools/prebuilts.bzl <<EOF
"Generated during release by release_prep.sh, using integrity.jq"

VERSION = "${TAG:1}"
PREFIX=$PREFIX ${SCRIPT_DIR}/generate_tools_versions.sh

REPO_URL = "${REPO_URL}"
cat >${PREFIX}/tools/integrity.bzl <<EOF
"Generated during release by release_prep.sh, using integrity.jq"
PREBUILTS = $(jq \
--from-file .github/workflows/integrity.jq \
--slurp \
--raw-input artifacts/*.sha256 \
)
EOF

# Append that generated file back into the archive
tar --file $ARCHIVE_TMP --append ${PREFIX}/bazeldnf/private/prebuilts.bzl
# Append that generated files back into the archive
tar --file $ARCHIVE_TMP --append ${PREFIX}/tools/version.bzl
tar --file $ARCHIVE_TMP --append ${PREFIX}/tools/integrity.bzl

# END patch up the archive
############

gzip < $ARCHIVE_TMP > $ARCHIVE
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')

# Set by GH actions, see
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
REPO_URL="${GITHUB_REPOSITORY:-rmohr/bazeldnf}"

cat << EOF
## Using [Bzlmod] with Bazel 6:
Add to your \`MODULE.bazel\` file:
\`\`\`starlark
bazel_dep(name = "bazeldnf", version = "${TAG:1}")
bazel_dep(name = "bazeldnf", version = "${GITHUB_REF_NAME:1}")
\`\`\`
This will register a prebuilt bazeldnf
Expand All @@ -73,7 +80,7 @@ http_archive(
name = "bazeldnf",
sha256 = "${SHA}",
strip_prefix = "${PREFIX}",
url = "https://github.com/${REPO_URL}/releases/download/${TAG}/${ARCHIVE}",
url = "https://github.com/${REPO_URL}/releases/download/${GITHUB_REF_NAME}/${ARCHIVE}",
)
load(
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ dist
cmd/cmd
.bazelrc.user
tools/release
artifacts
bazeldnf-v*

# ignore by now
MODULE.bazel.lock
4 changes: 2 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ bazeldnf(
rpmtree(
name = "something",
rpms = [
"@libvirt-libs-6.1.0-2.fc32.x86_64.rpm//rpm",
"@libvirt-devel-6.1.0-2.fc32.x86_64.rpm//rpm",
"@bazeldnf-dev-rpms//:libvirt-libs-6.1.0-2.fc32.x86_64.rpm",
"@bazeldnf-dev-rpms//:libvirt-devel-6.1.0-2.fc32.x86_64.rpm",
],
)

Expand Down
32 changes: 31 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ module(

bazeldnf = use_extension("//bazeldnf:extensions.bzl", "bazeldnf")
bazeldnf.toolchain()
use_repo(bazeldnf, "bazeldnf_toolchains")
use_repo(
bazeldnf,
"bazeldnf_toolchains",
)

register_toolchains("@bazeldnf_toolchains//:all")

bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "bazel_features", version = "1.13.0")

bazel_dep(name = "gazelle", version = "0.37.0", dev_dependency = True)
bazel_dep(name = "rules_go", version = "0.49.0", dev_dependency = True, repo_name = "io_bazel_rules_go")
Expand Down Expand Up @@ -41,3 +45,29 @@ use_repo(
"io_k8s_sigs_yaml",
"org_golang_x_crypto",
)

bazeldnf_dev = use_extension("//bazeldnf:extensions.bzl", "bazeldnf", dev_dependency = True)
bazeldnf_dev.alias(
name = "bazeldnf-dev-rpms",
dev_dependency = True,
)
bazeldnf_dev.rpm(
name = "libvirt-libs-6.1.0-2.fc32.x86_64.rpm",
sha256 = "3a0a3d88c6cb90008fbe49fe05e7025056fb9fa3a887c4a78f79e63f8745c845",
urls = [
"https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/32/Everything/x86_64/os/Packages/l/libvirt-libs-6.1.0-2.fc32.x86_64.rpm",
"https://storage.googleapis.com/builddeps/3a0a3d88c6cb90008fbe49fe05e7025056fb9fa3a887c4a78f79e63f8745c845",
],
)
bazeldnf_dev.rpm(
name = "libvirt-devel-6.1.0-2.fc32.x86_64.rpm",
sha256 = "2ebb715341b57a74759aff415e0ff53df528c49abaa7ba5b794b4047461fa8d6",
urls = [
"https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/32/Everything/x86_64/os/Packages/l/libvirt-devel-6.1.0-2.fc32.x86_64.rpm",
"https://storage.googleapis.com/builddeps/2ebb715341b57a74759aff415e0ff53df528c49abaa7ba5b794b4047461fa8d6",
],
)
use_repo(
bazeldnf_dev,
"bazeldnf-dev-rpms",
)
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gazelle:
bazelisk run //:gazelle

test: gazelle
bazelisk build --config=built-toolchain //... && bazelisk test --config=built-toolchain //...
bazelisk build //... && bazelisk test //...

buildifier:
bazelisk run //:buildifier
Expand All @@ -18,7 +18,9 @@ gofmt:
e2e:
(cd e2e/bazel-5 && bazelisk build //...)
(cd e2e/bazel-6 && bazelisk build //...)
(cd e2e/bazel-6-bzlmod && bazelisk build //...)
(cd e2e/bazel-7 && bazelisk build //...)
(cd e2e/bazel-7-bzlmod && bazelisk build //...)

fmt: gofmt buildifier

Expand Down
4 changes: 0 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
workspace(name = "bazeldnf")

load(":test_deps.bzl", "bazeldnf_test_dependencies")

bazeldnf_test_dependencies()
Loading

0 comments on commit 0916a06

Please sign in to comment.