Skip to content

Commit

Permalink
feat: automatic pr for successful (#793)
Browse files Browse the repository at this point in the history
Co-authored-by: sa-github-api <138766536+sa-github-api@users.noreply.github.com>
  • Loading branch information
NikolaMilosa and sa-github-api committed Aug 26, 2024
1 parent 5b6765b commit 4ce76af
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 37 deletions.
44 changes: 43 additions & 1 deletion .github/workflows/qualify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event.inputs.version || github.ref }}
cancel-in-progress: true

env:
AUTO_UPDATE_BRANCH: "auto-update-rel-index"

jobs:
setup:
runs-on:
Expand Down Expand Up @@ -73,7 +76,6 @@ jobs:
- name: "⚙️ Uploading artifacts created during qualification"
uses: actions/upload-artifact@v4
if: always()
with:
name: ${{ inputs.version }}-${{ matrix.version }}
path: /tmp/qualifier-artifacts/${{ inputs.version }}
Expand All @@ -85,6 +87,10 @@ jobs:
runs-on: ubuntu-22.04
if: always()
steps:
- uses: actions/checkout@v4
with:
repository: "dfinity/dre" # this needs to be specified so it can be kicked off from the ic repo

- name: "Get current date"
id: date
shell: bash
Expand Down Expand Up @@ -139,3 +145,39 @@ jobs:
Artifacts can be found on <https://drive.google.com/drive/u/1/folders/${{secrets.ARTIFACTS_DRIVE_FOLDER_ID}}|Google Drive :open_file_folder:>
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_API_TOKEN }}

- name: "Modify release index"
if: ${{ needs.qualify.result == 'success' }}
id: modify
shell: bash
run: |
pip install ruamel.yaml
BRANCH_REF=$(git ls-remote --heads https://github.com/dfinity/dre.git refs/heads/${AUTO_UPDATE_BRANCH})
if [ -z "$BRANCH_REF" ]; then
echo "Branch $BRANCH_REF does not exist, creating..."
git checkout -b $BRANCH_REF
echo "SHOULD_CREATE_PR=true" >> $GITHUB_OUTPUT
else
echo "Branch $BRANCH_REF exists"
git checkout $BRANCH_REF
echo "SHOULD_CREATE_PR=false" >> $GITHUB_OUTPUT
# Cache current version of script to be able to force checkout main
# If testing it is usually hard to get the version correct so this is
# a workaround
cp scripts/auto-update-release-index.py /tmp/auto-update-release-index.py
git fetch origin main --depth 1
git checkout main
python /tmp/auto-update-release-index.py ${{ inputs.version }} ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: "Create/Update PR after a successful rc cut"
if: ${{ needs.qualify.result == 'success' && steps.modify.outputs.SHOULD_CREATE == 'true' }}
uses: peter-evans/create-pull-request@v6
with:
commit-message: "chore: Update `release-index.yaml` after a successful rc cut of ${{ inputs.version }}"
branch: ${{ env.AUTO_UPDATE_BRANCH }}
title: "chore: Update `release-index.yaml`"
body: "This PR updates `release-index.yaml` after a successful rc cut"
token: ${{ secrets.GIX_CREATE_PR_PAT }}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ slackblocks = "^1.0.10"
aiohttp = "^3.10.3"
quart = "^0.19.6"
pytest-asyncio = "^0.24.0"
ruamel-yaml = "^0.18.6"
pytest-xdist = "^3.6.1"

[tool.poetry.group.dev.dependencies]
Expand Down
72 changes: 36 additions & 36 deletions release-index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,69 +49,69 @@ releases:
version: 0d2b3965c813cd3a39ceedacd97fa2eee8760074
- rc_name: rc--2024-07-03_23-01
versions:
- # Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1360352158
name: base
# Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1360352158
- name: base
version: e4eeb331f874576126ef1196b9cdfbc520766fbd
- # Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1360514977
name: storage-layer-disabled
# Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1360514977
- name: storage-layer-disabled
version: 5849c6daf2037349bd36dcb6e26ce61c2c6570d0
- # Successful qualification pipeline: https://github.com/dfinity-ops/release/actions/runs/9877005239/job/27277530675
name: hotfix-https-outcalls
# Successful qualification pipeline: https://github.com/dfinity-ops/release/actions/runs/9877005239/job/27277530675
- name: hotfix-https-outcalls
version: 16fabfd24617be66e08e00abc7ba3136bbd80010
- # Successful qualification pipeline: https://github.com/dfinity-ops/release/actions/runs/9880530622/job/27289909086
name: hotfix-https-outcalls-with-lsmt
# Successful qualification pipeline: https://github.com/dfinity-ops/release/actions/runs/9880530622/job/27289909086
- name: hotfix-https-outcalls-with-lsmt
version: 7dee90107a88b836fc72e78993913988f4f73ca2
- rc_name: rc--2024-06-26_23-01
versions:
- # Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1350685950
name: base
# Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1350685950
- name: base
version: 2e269c77aa2f6b2353ddad6a4ac3d5ddcac196b1
- # Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1350889767
name: storage-layer-disabled
# Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1350889767
- name: storage-layer-disabled
version: b6c3687fb3a03ca65fcd49f0aadc499367904c8b
- rc_name: rc--2024-06-19_23-01
versions:
- # Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/jobs/7147033611
name: base
# Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/jobs/7147033611
- name: base
version: e3fca54d11e19dc7134e374d9f472c5929f755f9
- # Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/jobs/7147621252
name: storage-layer-disabled
# Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/jobs/7147621252
- name: storage-layer-disabled
version: ae3c4f30f198eba9c5b113ec32fdec90713c24a0
- # Ongoing qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1345332930
# This cut will only be rolled out to lhg73.
name: cycle-hotfix
# Ongoing qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1345332930
# This cut will only be rolled out to lhg73.
- name: cycle-hotfix
version: 9c006a50d364edf1403ef50b24c3be39dba8a5f6
- rc_name: rc--2024-06-12_23-01
versions:
- # Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/jobs/7098651594
name: base
# Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/jobs/7098651594
- name: base
version: 246d0ce0784d9990c06904809722ce5c2c816269
- # Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/jobs/7114764016
name: storage-layer-disabled
# Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/jobs/7114764016
- name: storage-layer-disabled
version: 2dfe3a1864d1b9a6df462e9503adf351036e7965
- # Ongoing qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1345332852
# This cut will only be rolled out to lhg73.
name: cycle-hotfix
# Ongoing qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1345332852
# This cut will only be rolled out to lhg73.
- name: cycle-hotfix
version: 48c500d1501e4165fc183e508872a2ef13fd0bef
- rc_name: rc--2024-06-05_23-01
versions:
- # Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/jobs/7033661917
name: base
# Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/jobs/7033661917
- name: base
version: d19fa446ab35780b2c6d8b82ea32d808cca558d5
- # Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/jobs/7113921560
name: storage-layer-disabled
# Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/jobs/7113921560
- name: storage-layer-disabled
version: 08f32722df2f56f1e5c1e603fee0c87c40b77cba
- rc_name: rc--2024-05-29_23-02
versions:
- # Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1311667262
name: base
# Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1311667262
- name: base
version: b9a0f18dd5d6019e3241f205de797bca0d9cc3f8
- name: hotfix-nns
version: 42284da596a2596361f305b8d6d6097b0f40e6d6
- rc_name: rc--2024-05-22_23-01
versions:
- # Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1302061674
name: base
# Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1302061674
- name: base
version: ec35ebd252d4ffb151d2cfceba3a86c4fb87c6d6
- rc_name: rc--2024-05-15_23-02
versions:
Expand Down Expand Up @@ -150,11 +150,11 @@ releases:
version: 5e285dcaf77db014ac85d6f96ff392fe461945f5
- rc_name: rc--2024-04-17_23-01
versions:
# Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1258259180
- name: base
# Successful qualification pipeline: https://gitlab.com/dfinity-lab/core/release/-/pipelines/1258259180
version: abcea3eff0be52dc5328e71de98288991de854bf
# Qualification pipeline in progress at the time this record was created.
- name: query-stats
# Qualification pipeline in progress at the time this record was created.
version: 0a51fd74f08b2e6f23d6e1d60f1f52eb73b40ccc
- name: hotfix-bitcoin
version: 687de34189de20c5346e6b6167d22bcdd11e7ae5
Expand Down
102 changes: 102 additions & 0 deletions scripts/auto-update-release-index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import argparse
import re
import subprocess

import ruamel.yaml
from ruamel.yaml.main import YAML


def get_toplevel() -> str:
return subprocess.run(
["git", "rev-parse", "--show-toplevel"], capture_output=True, text=True, check=True
).stdout.strip()


def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser("Automatic update of release index")
parser.add_argument("commit", help="Commit of the release, it will be used to determine the rc")
parser.add_argument("link", help="Link to the pipeline of qualification job")
return parser.parse_args()


def get_branch_with_commit(commit: str) -> str:
output = subprocess.run(
["git", "ls-remote", "--branches", "https://github.com/dfinity/ic.git"],
capture_output=True,
text=True,
check=True,
).stdout.strip()

branch = list(filter(lambda line: line.startswith(commit), output.splitlines()))[0].split("/")[-1]
return branch


def parse_branch(branch: str) -> tuple[str, str]:
pattern = re.compile(r"^(rc--\d{4}-\d{2}-\d{2}_\d{2}-\d{2})(?:-(.*))?$")
matches = pattern.match(branch)
if not matches:
raise ValueError("Input branch is not in the correct format `rc--%Y-%m-%d_%H-%M(-feature)")

name = matches.group(1)
feature = matches.group(2)
if not feature:
feature = "base"

return (name, feature)


def pop_rcs_not_found_on_main(rc_name: str, index, yaml: YAML):
# Remove all rcs not found on main unless its the same release as the potential added one.
#
# This can happen if the rc that is being added has a base and feature versions
output = subprocess.run(["git", "show", "main:release-index.yaml"], capture_output=True, text=True)
if output.returncode != 0:
raise ValueError(f"Unexpected response from git: \n{output.stderr.strip()}")
index_on_main = output.stdout.strip()
index_on_main = yaml.load(index_on_main)
rcs_on_main = [rc["rc_name"] for rc in index_on_main["releases"]]
index["releases"] = [rc for rc in index["releases"] if rc["rc_name"] in rcs_on_main or rc["rc_name"] == rc_name]


def main():
args = parse_args()

try:
branch = get_branch_with_commit(args.commit)
print(f"Found branch: {branch}")
except Exception as e:
print(f"Didn't find branch with head {args.commit}, Error: {e}")
exit(1)

try:
(rc_name, tag) = parse_branch(branch)
except ValueError as e:
print(e)
exit(1)

index_path = f"{get_toplevel()}/release-index.yaml"
yaml = YAML(typ="rt")
yaml.indent(mapping=4, sequence=4, offset=2)
index = yaml.load(open(index_path, "r").read())
try:
pop_rcs_not_found_on_main(rc_name, index, yaml)
except Exception as e:
print(f"Error: {e}")
exit(1)

releases = index["releases"]
elem_to_add = {"name": tag, "version": args.commit}
elem_to_add = ruamel.yaml.CommentedMap(elem_to_add)
elem_to_add.yaml_set_start_comment(f"Qualification pipeline:\n# {args.link}", indent=6)

potential_release = next(filter(lambda release: release["rc_name"] == rc_name, releases), None)
if not potential_release:
potential_release = ruamel.yaml.CommentedMap({"rc_name": rc_name, "versions": []})
releases.insert(0, potential_release)

potential_release["versions"].append(elem_to_add)
yaml.dump(index, open(index_path, "w"))


if __name__ == "__main__":
main()

0 comments on commit 4ce76af

Please sign in to comment.