Skip to content

Commit

Permalink
build: integrate builtin_metadata.json handling in release process
Browse files Browse the repository at this point in the history
Fixes #4754.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
  • Loading branch information
srenatus committed Jun 20, 2022
1 parent c54ddd3 commit a89cf69
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
13 changes: 11 additions & 2 deletions Makefile
Expand Up @@ -168,6 +168,15 @@ clean: wasm-lib-clean
fuzz:
go test ./ast -fuzz FuzzParseStatementsAndCompileModules -fuzztime ${FUZZ_TIME} -v -run '^$$'

.PHONY: update-builtin-metadata-release
update-builtin-metadata-release:
build/update-version.sh "$(VERSION)"
make generate

.PHONY: update-builtin-metadata-dev
update-builtin-metadata-dev:
build/update-version.sh "$(VERSION)-dev"
make generate

######################################################
#
Expand Down Expand Up @@ -479,7 +488,7 @@ check-go-module:
######################################################

.PHONY: release-patch
release-patch:
release-patch: update-builtin-metadata-release
ifeq ($(GITHUB_TOKEN),)
@echo "\033[0;31mGITHUB_TOKEN environment variable missing.\033[33m Provide a GitHub Personal Access Token (PAT) with the 'read:org' scope.\033[0m"
endif
Expand All @@ -491,7 +500,7 @@ endif
/_src/build/gen-release-patch.sh --version=$(VERSION) --source-url=/_src

.PHONY: dev-patch
dev-patch:
dev-patch: update-builtin-metadata-dev
@$(DOCKER) run $(DOCKER_FLAGS) \
-v $(PWD):/_src \
python:2.7 \
Expand Down
6 changes: 3 additions & 3 deletions build/gen-dev-patch.sh
Expand Up @@ -39,8 +39,8 @@ cd $OPA_DIR

LAST_VERSION=$(git describe --abbrev=0 --tags | cut -c 2-)

update_makefile() {
sed -i='' -e "s/Version\s\+=\s\+\".\+\"$/Version = \"$VERSION-dev\"/" version/version.go
update_version() {
./build/update-version.sh "$VERSION-dev"
}

update_changelog() {
Expand All @@ -57,7 +57,7 @@ EOF
}

main() {
update_makefile
update_version
update_changelog
git --no-pager diff --no-color
}
Expand Down
12 changes: 9 additions & 3 deletions build/gen-release-patch.sh
Expand Up @@ -41,8 +41,8 @@ if [ -z "$LAST_VERSION" ]; then
LAST_VERSION=$(git describe --abbrev=0 --tags)
fi

update_makefile() {
sed -i='' -e "s/Version\s\+=\s\+\".\+\"$/Version = \"$VERSION\"/" version/version.go
update_version() {
./build/update-version.sh "$VERSION"
}

update_changelog() {
Expand Down Expand Up @@ -76,10 +76,16 @@ update_capabilities() {
git add --intent-to-add capabilities/v$VERSION.json
}

update_metadata() {
cp $SOURCE_URL/builtin_metadata.json $OPA_DIR
git add --intent-to-add builtin_metadata.json
}

main() {
update_makefile
update_version
update_changelog
update_capabilities
update_metadata
git --no-pager diff --no-color
}

Expand Down
2 changes: 1 addition & 1 deletion build/get-build-version.sh
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

grep '^var Version' version/version.go | awk '{print $4}' | tr -d '"'
awk -F'"' '/^var Version/{print $2}' version/version.go
6 changes: 6 additions & 0 deletions build/update-version.sh
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -e
# NOTE(sr): This was the only way I've found to replace the string
# reliably on OSX and Linux.
perl -pi -e "s/Version = \".*\"$/Version = \"$1\"/" version/version.go
7 changes: 4 additions & 3 deletions docs/devel/RELEASE.md
Expand Up @@ -185,6 +185,7 @@ Once the Pull Request has merged fetch the latest changes and tag the commit to
prepare for publishing. Use the same instructions as defined above in normal
release [publishing](#publishing) guide (being careful to tag the appropriate commit).

Last step is to copy the CHANGELOG snippet and capabilities.json for the version to `main`. Create
a new PR with the version information added below the `Unreleased` section. Remove
any `Unreleased` notes if they were included in the bugfix release.
Last step is to copy the CHANGELOG snippet and generated files
(builtin_metadata.json and capabilities.json) for the version to `main`. Create
a new PR with the version information added below the `Unreleased` section.
Remove any `Unreleased` notes if they were included in the bugfix release.
7 changes: 6 additions & 1 deletion internal/cmd/genbuiltinmetadata/main.go
Expand Up @@ -13,11 +13,16 @@ import (
"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/internal/compiler/wasm"
"github.com/open-policy-agent/opa/types"
"github.com/open-policy-agent/opa/version"
)

func main() {
f := ast.CapabilitiesForThisVersion()
sorted := append(sortedCaps(), versionedCaps{version: "edge", caps: f})
sorted := sortedCaps()
if !strings.HasSuffix(version.Version, "-dev") {
sorted = append(sorted, versionedCaps{version: "v" + version.Version, caps: f})
}
sorted = append(sorted, versionedCaps{version: "edge", caps: f})

mdata := make(map[string]interface{})
categories := make(map[string][]string)
Expand Down

0 comments on commit a89cf69

Please sign in to comment.