feat: create a github action to create a bcr entry #26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# End-to-end tests for the Publish to BCR custom GitHub action | |
name: action-e2e | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
workflow_dispatch: | |
concurrency: | |
# Cancel previous actions from the same PR or branch except 'main' branch. | |
# See https://docs.github.com/en/actions/using-jobs/using-concurrency and https://docs.github.com/en/actions/learn-github-actions/contexts for more info. | |
group: concurrency-group::${{ github.workflow }}::${{ github.event.pull_request.number > 0 && format('pr-{0}', github.event.pull_request.number) || github.ref_name }}${{ github.ref_name == 'main' && format('::{0}', github.run_id) || ''}} | |
cancel-in-progress: ${{ github.ref_name != 'main' }} | |
jobs: | |
# Each job is an e2e test. Unfortunately a full workflow cannot be added as | |
# required status check on branch protection rules, so each test must be added | |
# as a required check: https://github.com/orgs/community/discussions/12395. | |
test-e2e-happy-path: | |
# Create a new module entry and test the content | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
path: this | |
- name: Setup test fixture | |
run: | | |
set -o errexit -o nounset -o pipefail -o xtrace | |
# Create a release archive from a fixture | |
tar -czvf archive.tar.gz -C this/e2e/fixtures/versioned --transform 's,^./,versioned-1.0.0/,' --sort=name --owner=root:0 --group=root:0 --mtime='UTC 1980-02-01' . | |
# Substitute the archive url to a local file path | |
cat this/e2e/fixtures/versioned/.bcr/source.template.json | jq ".url = \"file://$(realpath archive.tar.gz)\"" > "/tmp/source.template.json" | |
mv /tmp/source.template.json this/e2e/fixtures/versioned/.bcr/source.template.json | |
cat this/e2e/fixtures/versioned/.bcr/source.template.json | |
- name: Create registry | |
run: | | |
mkdir -p bazel-central-registry/modules | |
cd bazel-central-registry | |
git init | |
- name: Create entry | |
uses: ./this | |
with: | |
tag: v1.0.0 | |
module-version: 1.0.0 | |
github-repository: foobar/versioned | |
templates-dir: this/e2e/fixtures/versioned/.bcr | |
local-registry: bazel-central-registry | |
- name: Test entry content | |
run: |- | |
set -o errexit -o nounset -o pipefail -o xtrace | |
mkdir -p expected/1.0.0 | |
cat > expected/metadata.json <<- EOF | |
{ | |
"homepage": "https://github.com/testorg/versioned", | |
"maintainers": [ | |
{ | |
"name": "Foo McBar", | |
"email": "[email protected]", | |
"github": "foobar" | |
} | |
], | |
"repository": [ | |
"github:testorg/versioned" | |
], | |
"versions": [ | |
"1.0.0" | |
], | |
"yanked_versions": {} | |
} | |
EOF | |
cat > expected/1.0.0/MODULE.bazel <<- EOF | |
module( | |
name = "versioned", | |
version = "1.0.0", | |
) | |
EOF | |
cat > expected/1.0.0/source.json <<- EOF | |
{ | |
"integrity": "sha256-t39EUhiPjM65oWhYtLQ2dq4fWDU/oQ0L/DNBvYkNfyk=", | |
"strip_prefix": "versioned-1.0.0", | |
"url": "file:///home/runner/work/publish-to-bcr/publish-to-bcr/archive.tar.gz" | |
} | |
EOF | |
cat > expected/1.0.0/presubmit.yml <<- EOF | |
bcr_test_module: | |
module_path: "e2e/bzlmod" | |
matrix: | |
platform: ["debian10", "macos", "ubuntu2004", "windows"] | |
bazel: [6.x, 7.x] | |
tasks: | |
run_tests: | |
name: "Run test module" | |
platform: ${{ '\${{ platform }}' }} | |
bazel: ${{ '\${{ bazel }}' }} | |
test_targets: | |
- "//..." | |
EOF | |
diff -r bazel-central-registry/modules/versioned expected | |
test-github-repository-default: | |
# Test that the `github-repository` input defaults to ${{ github.repository }} | |
# indirectly by checking the resulting subtituted source.json file in the entry. | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
path: this | |
- name: Setup test fixture | |
run: | | |
set -o errexit -o nounset -o pipefail -o xtrace | |
# Create a release archive from a fixture, setting the prefix to be | |
# publish-to-bcr-1.0.0 (the name of this repository) since we are testing | |
# the default of `github-repository` which is the repo that the action executes in. | |
tar -czvf archive.tar.gz -C this/e2e/fixtures/versioned --transform 's,^./,publish-to-bcr-1.0.0/,' . | |
# Substitute the archive url to a local file path | |
cat this/e2e/fixtures/versioned/.bcr/source.template.json | jq ".url = \"file://$(realpath archive.tar.gz)\"" > "/tmp/source.template.json" | |
mv /tmp/source.template.json this/e2e/fixtures/versioned/.bcr/source.template.json | |
cat this/e2e/fixtures/versioned/.bcr/source.template.json | |
- name: Create registry | |
run: | | |
mkdir -p bazel-central-registry/modules | |
cd bazel-central-registry | |
git init | |
- name: Create entry | |
uses: ./this | |
with: | |
tag: v1.0.0 | |
module-version: 1.0.0 | |
templates-dir: this/e2e/fixtures/versioned/.bcr | |
local-registry: bazel-central-registry | |
- name: Test repository substitution | |
run: |- | |
set -o errexit -o nounset -o pipefail -o xtrace | |
STRIP_PREFIX="$(cat bazel-central-registry/modules/versioned/1.0.0/source.json | jq -r ".strip_prefix")" | |
EXPECTED="publish-to-bcr-1.0.0" | |
if [ "${STRIP_PREFIX}" != "${EXPECTED}" ]; then | |
echo "Incorrect strip prefix" | |
echo "Expected ${EXPECTED} but got ${STRIP_PREFIX}" | |
exit 1 | |
fi | |
echo "Success" |