Browse Source

Merge pull request #16358 from abpframework/update-latest-version

Create a github action to update latest-versions.json file
pull/16367/head
Engincan VESKE 3 years ago
committed by GitHub
parent
commit
d069cf3205
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 52
      .github/scripts/update_versions.py
  2. 29
      .github/workflows/update-versions.yml

52
.github/scripts/update_versions.py

@ -0,0 +1,52 @@
import os
import json
from github import Github
def update_latest_versions():
version = os.environ["GITHUB_REF"].split("/")[-1]
if "rc" not in version:
return False
with open("latest-versions.json", "r") as f:
latest_versions = json.load(f)
latest_versions[0]["version"] = version
with open("latest-versions.json", "w") as f:
json.dump(latest_versions, f, indent=2)
return True
def create_pr():
g = Github(os.environ["GITHUB_TOKEN"])
repo = g.get_repo("abpframework/abp")
branch_name = f"update-latest-versions-{os.environ['GITHUB_REF'].split('/')[-1]}"
base = repo.get_branch("dev")
repo.create_git_ref(ref=f"refs/heads/{branch_name}", sha=base.commit.sha)
# Get the current latest-versions.json file and its sha
contents = repo.get_contents("latest-versions.json", ref="dev")
file_sha = contents.sha
# Update the file in the repo
repo.update_file(
path="latest-versions.json",
message=f"Update latest-versions.json to version {os.environ['GITHUB_REF'].split('/')[-1]}",
content=open("latest-versions.json", "r").read().encode("utf-8"),
sha=file_sha,
branch=branch_name,
)
pr = repo.create_pull(title="Update latest-versions.json",
body="Automated PR to update the latest-versions.json file.",
head=branch_name, base="dev")
pr.create_review_request(reviewers=["ebicoglu", "gizemmutukurt", "skoc10"])
if __name__ == "__dev__":
should_create_pr = update_latest_versions()
if should_create_pr:
create_pr()

29
.github/workflows/update-versions.yml

@ -0,0 +1,29 @@
name: Update Latest Versions
on:
release:
types:
- published
jobs:
update-versions:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install PyGithub
- name: Update latest-versions.json and create PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python .github/scripts/update_versions.py
Loading…
Cancel
Save