Skip to content

Commit

Permalink
ci: Uncheck prerelease status for patch releases
Browse files Browse the repository at this point in the history
Signed-off-by: Willem Pienaar <git@willem.co>
  • Loading branch information
woop committed Mar 5, 2022
1 parent 076fa7a commit e6b5d5a
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
19 changes: 18 additions & 1 deletion .releaserc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,29 @@ possible_branches = [{name: "master"}, {name: current_branch}]
module.exports = {
branches: possible_branches,
plugins: [
// Try to guess the type of release we should be doing (minor, patch)
"@semantic-release/commit-analyzer",

["@semantic-release/exec", {
// Validate the type of release we are doing
"verifyReleaseCmd": "./infra/scripts/validate-release.sh ${nextRelease.type} " + current_branch,
"prepareCmd": "python ./infra/scripts/version_bump/bump_file_versions.py ${lastRelease.version} ${nextRelease.version}"

// Bump all version files
"prepareCmd": "python ./infra/scripts/release/bump_file_versions.py ${lastRelease.version} ${nextRelease.version}"
}],

"@semantic-release/release-notes-generator",

// Update the changelog
[
"@semantic-release/changelog",
{
changelogFile: "CHANGELOG.md",
changelogTitle: "# Changelog",
}
],

// Make a git commit, tag, and push the changes
[
"@semantic-release/git",
{
Expand All @@ -46,6 +56,8 @@ module.exports = {
message: "chore(release): release ${nextRelease.version}\n\n${nextRelease.notes}"
}
],

// Publish a GitHub release (but don't spam issues/PRs with comments)
[
"@semantic-release/github",
{
Expand All @@ -55,6 +67,11 @@ module.exports = {
labels: false,
}
],

// For some reason all patches are tagged as pre-release. This step undoes that.
["@semantic-release/exec", {
"publishCmd": "python ./infra/scripts/release/unset_prerelease.py ${nextRelease.version}"
}],
]
}

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def main() -> None:

# Get git repo root directory
repo_root = pathlib.Path(__file__).resolve().parent.parent.parent.parent
path_to_file_list = repo_root.joinpath("infra", "scripts", "version_bump", "files_to_bump.txt")
path_to_file_list = repo_root.joinpath("infra", "scripts", "release", "files_to_bump.txt")

# Get files to bump versions within
with open(path_to_file_list, "r") as f:
Expand Down
File renamed without changes.
70 changes: 70 additions & 0 deletions infra/scripts/release/unset_prerelease.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# For some reason patch releases with Semantic Release are tagged as "pre-release" on GitHub. This script
# removes the "pre-release" tag from the release.
import os
import sys
import requests

USAGE = f"Usage: python {sys.argv[0]} [--help] | version_being_released (e.g., v0.19.1)]"


def get_prerelease_status(version_being_released, token):
url = f"https://api.github.com/repos/feast-dev/feast/releases/tags/v{version_being_released}"

headers = {
"Content-Type": "application/json",
"Accept": "application/vnd.github.v3+json",
"Authorization": f"Bearer {token}"
}

response = requests.request("GET", url, headers=headers)
response_json = response.json()
return bool(response_json['prerelease']), response_json['id']


def set_prerelease_status(release_id, status, token):
url = f"https://api.github.com/repos/feast-dev/feast/releases/{release_id}"

payload = {"prerelease": status}

headers = {
"Content-Type": "application/json",
"Accept": "application/vnd.github.v3+json",
"Authorization": f"Bearer {token}"
}

requests.request("PATCH", url, json=payload, headers=headers)


def main() -> None:
args = sys.argv[1:]
if not args or len(args) != 1:
raise SystemExit(USAGE)

version_being_released = args[0].strip() # should look like 0.19.1 (without the v)

print(f"Disabling prerelease status for {version_being_released}")

token = os.getenv('GITHUB_TOKEN', default=None)

if token is None:
raise OSError("GITHUB_TOKEN environmental variable is not set")

is_prerelease, release_id = get_prerelease_status(version_being_released, token)

if is_prerelease:
set_prerelease_status(release_id, False, token)
else:
print(f"{version_being_released} is not a pre-release, exiting.")
exit(0)

is_prerelease, release_id = get_prerelease_status(version_being_released, token)

if is_prerelease:
import warnings
warnings.warn(f"Failed to unset prerelease status for {version_being_released} release id {release_id}")
else:
print(f"Successfully unset prerelease status for {version_being_released} release id {release_id}")


if __name__ == "__main__":
main()

0 comments on commit e6b5d5a

Please sign in to comment.