Skip to content

Commit

Permalink
fix release script
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-aksamentov committed Jan 16, 2024
1 parent 76cdeb8 commit 72c123a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ env:

jobs:
build-and-deploy-datasets:
runs-on: ubuntu-22.04
runs-on: ubuntu-20.04

environment:
name: ${{ github.ref }}
Expand All @@ -37,6 +37,7 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-2
GH_TOKEN: ${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_REPO }}

steps:
- name: "Checkout code"
Expand All @@ -47,18 +48,18 @@ jobs:

- name: "Authenticate git"
run: |
export GITHUB_TOKEN="${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_REPO }}"
# export GITHUB_TOKEN="${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_REPO }}"
export BOT_GIT_USER_EMAIL="${{ secrets.BOT_GIT_USER_EMAIL }}"
export BOT_GIT_USER_NAME="${{ secrets.BOT_GIT_USER_NAME }}"

: ${GITHUB_TOKEN?"The env var GITHUB_TOKEN is required"}
: ${BOT_GIT_USER_EMAIL?"The env var BOT_GIT_USER_EMAIL is required"}
: ${BOT_GIT_USER_NAME?"The env var BOT_GIT_USER_NAME is required"}
# : ${GITHUB_TOKEN?"The env var GITHUB_TOKEN is required"}
# : ${BOT_GIT_USER_EMAIL?"The env var BOT_GIT_USER_EMAIL is required"}
# : ${BOT_GIT_USER_NAME?"The env var BOT_GIT_USER_NAME is required"}

git config --global user.email "${BOT_GIT_USER_EMAIL}"
git config --global user.name "${BOT_GIT_USER_NAME}"

gh auth setup-git >/dev/null
# gh auth setup-git >/dev/null

- name: "Extract branch name"
run: |
Expand Down Expand Up @@ -95,6 +96,7 @@ jobs:
- name: "Rebuild, commit, push and make a release"
if: github.ref == 'refs/heads/release'
run: |
echo ${{ secrets.GH_TOKEN_NEXTSTRAIN_BOT_REPO }} | gh auth login --with-token
./scripts/rebuild --input-dir 'data/' --output-dir 'data_output/' --release --repo="${GITHUB_REPOSITORY}"
- name: "Deploy dataset server"
Expand Down
8 changes: 3 additions & 5 deletions scripts/lib/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ def changelog_get_unreleased_section(changelog_path: str):


def format_dataset_attributes_md_table(attributes):
attr_table = f"| {'attribute':20} | {'value':20} | {'value friendly':40} |\n"
attr_table += f"| {'-' * 20} | {'-' * 20} | {'-' * 40} |\n"
attr_table = f"| {'attribute':20} | {'value':40} |\n"
attr_table += f"| {'-' * 20} | {'-' * 40} |\n"
for attr_name, attr_val in attributes.items():
value = attr_val["value"]
value_friendly = dict_get(attr_val, ["valueFriendly"]) or ""
attr_table += f'| {attr_name:20} | {value:20} | {value_friendly:40} |\n'
attr_table += f'| {attr_name:20} | {attr_val:40} |\n'
return attr_table
40 changes: 24 additions & 16 deletions scripts/rebuild
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,13 @@ def main():
commit_hash = commit_changes(args, tag, release_infos)

if args.push:
l.info("Pushing commited changes to GitHub")
git_push()

if args.release:
l.info("Releasing to GitHub")
release_notes = aggregate_release_notes(release_infos)
l.info(f"Release notes:\n-------\n{release_notes}\n-------\nEnd of release notes\n")
publish_to_github_releases(args, tag, commit_hash, release_notes)


Expand Down Expand Up @@ -351,26 +354,35 @@ def prepare_dataset_release_infos(args, datasets, collection_dir, tag, updated_a


def aggregate_release_notes(release_infos):
dataset_names_friendly = format_list(
unique([get_dataset_name_friendly(release_info["dataset"]) for release_info in release_infos]),
sep="\n", marker="- ", quote=False
)
release_notes = f"This release contains changes for datasets:\n\n{dataset_names_friendly}\n\n\n"
dataset_list = format_dataset_list(release_infos)
release_notes = f"This release contains changes for datasets:\n\n{dataset_list}\n\n\n"
for release_info in release_infos:
release_notes += f'\n{release_info["release_notes"]}\n\n'
return release_notes


def format_dataset_list(release_infos):
entries = [format_dataset_list_entry(release_info) for release_info in release_infos]
entries = unique(entries)
entries = list(sorted(entries))
return format_list(entries, sep="\n", marker="- ", quote=False)


def format_dataset_list_entry(release_info):
path = dict_get_required(release_info, ['dataset', 'path'])
name = get_dataset_name_friendly(release_info['dataset'])
return f"{path} ({name})"


def commit_changes(args, tag, release_infos):
l.info(f"Commiting changes for '{tag}'")
l.info(f"Committing changes for '{tag}'")

commit_message = "chore: rebuild [skip ci]"
if args.release:
dataset_names = format_list(
unique([get_dataset_name(release_info["dataset"]) for release_info in release_infos]),
sep="\n", marker="- ", quote=False
)
commit_message = f"chore: release '{tag}'\n\nUpdated datasets:\n\n{dataset_names}"
dataset_list = format_dataset_list(release_infos)
commit_message = f"chore: release '{tag}'\n\nUpdated datasets:\n\n{dataset_list}"

l.info(f"Commit message:\n--------\n{commit_message}\n--------\nEnd of commit message\n\n")

return git_commit_all(commit_message)

Expand Down Expand Up @@ -438,12 +450,8 @@ def create_dataset_package(args, dataset, pathogen_json, tag, dataset_dir):
file_write("User-agent: *\nDisallow: /\n", join(args.output_dir, "robots.txt"))


def get_dataset_name(dataset):
return dict_get_required(dataset, ["attributes", "name", "value"])


def get_dataset_name_friendly(dataset):
return dict_get(dataset, ["attributes", "name", "valueFriendly"]) or get_dataset_name(dataset)
return dict_get_required(dataset, ["attributes", "name"])


if __name__ == '__main__':
Expand Down

0 comments on commit 72c123a

Please sign in to comment.