Skip to content

Commit

Permalink
fix(packaging): include missing .bzl files into the tar distribution (#…
Browse files Browse the repository at this point in the history
…36)

I had previously missed some .bzl files when refactoring the
packaging for BCR/etc. This adds a manual test script that can
be later reworked into a bazel-in-bazel integration test
  • Loading branch information
aignas authored Jan 10, 2024
1 parent 7a21c06 commit a2e56cc
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 63 deletions.
31 changes: 6 additions & 25 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ name: CI
on: # yamllint disable rule:truthy
push:
branches:
- master
- main
tags:
- "*.*.*"
pull_request:
branches:
- master
- main

jobs:
build:
Expand All @@ -33,39 +33,20 @@ jobs:
- name: Test
run: bazel test //...

examples:
runs-on: ubuntu-latest

strategy:
matrix:
example:
- check_glob
- optional_attributes

steps:
- uses: actions/checkout@v4

- name: Test
run: bazel test //...
working-directory: examples/${{ matrix.example }}

pkg:
runs-on: ubuntu-latest
needs:
- build
- test-mac
- examples

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Create release archive and notes
run: |
# Set by GH actions, see
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
bazel run \
--stamp --embed_label "${{ github.ref_name }}" \
//:release -- release
# Set by GH actions, see
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
run: ./ci/package.sh "${{ github.ref_name }}"

- name: Archive release artifacts
uses: actions/upload-artifact@v3
Expand Down
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ filegroup(
"MODULE.bazel",
"README.md",
"WORKSPACE",
":def.bzl",
":deps.bzl",
"//internal:distribution",
],
visibility = ["//internal/pkg:__pkg__"],
Expand Down
47 changes: 47 additions & 0 deletions ci/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
#
# TODO: use bazel integration test framework and rewrite this to be run by `bazel test`
set -euo pipefail

TMPDIR="$(mktemp -d)"
trap 'rm -rf -- "$TMPDIR"' EXIT

_log() {
echo "INFO: $*"
}

main() {
# First change the directory to workspace root
cd "$(dirname "$0")"/..

local -r version="${1:-0.0.0}"

# Then build the release artifact
local -r tarball=$(
bazel run \
--stamp --embed_label "$version" \
//:release -- release
)

_log "Extracting the tarball into a temporary directory to run examples"
tar -xvf "$tarball" -C "$TMPDIR"

# Then run examples with the packaged artifacts
examples=(
check_glob
optional_attributes
)

for example in "${examples[@]}"; do
_log "Running an example with the generated archive"
pushd "examples/$example"
bazel \
test \
--override_module rules_shellcheck="$TMPDIR" \
...
popd
done
_log "Success"
}

main "$@"
14 changes: 0 additions & 14 deletions examples/released_example/MODULE.bazel

This file was deleted.

12 changes: 0 additions & 12 deletions examples/released_example/WORKSPACE

This file was deleted.

7 changes: 0 additions & 7 deletions examples/released_example/src/BUILD.bazel

This file was deleted.

4 changes: 0 additions & 4 deletions examples/released_example/src/script.sh

This file was deleted.

6 changes: 5 additions & 1 deletion internal/pkg/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ mkdir -p "$DST"
RELEASE_ARCHIVE="$DST/rules_shellcheck-$GITHUB_REF_NAME.tar.gz"
RELEASE_NOTES="$DST/release_notes.md"

cp -v "$ARCHIVE" "$RELEASE_ARCHIVE"
cp -v "$ARCHIVE" "$RELEASE_ARCHIVE" >&2
chmod 644 "$RELEASE_ARCHIVE"
SHA=$(sha256sum "$RELEASE_ARCHIVE" | awk '{print $1}')

sed \
-e "s/%%TAG%%/$GITHUB_REF_NAME/g" \
-e "s/%%SHA256%%/$SHA/g" \
"${RELEASE_NOTES_TEMPLATE}" \
> "$RELEASE_NOTES"

# Output the release artifact path
echo "$RELEASE_ARCHIVE"

0 comments on commit a2e56cc

Please sign in to comment.