From 23205234b4e525a5c216ab706d608a954bf7b428 Mon Sep 17 00:00:00 2001 From: selmankoc Date: Mon, 19 Jun 2023 16:40:00 +0300 Subject: [PATCH] added action to publish release and update last version --- .github/scripts/update_versions.py | 54 +++++++++++++++++++++++++++ .github/workflows/publish-release.yml | 44 ++++++++++++++++++++++ .github/workflows/update-versions.yml | 33 ++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 .github/scripts/update_versions.py create mode 100644 .github/workflows/publish-release.yml create mode 100644 .github/workflows/update-versions.yml diff --git a/.github/scripts/update_versions.py b/.github/scripts/update_versions.py new file mode 100644 index 0000000000..04bddf361a --- /dev/null +++ b/.github/scripts/update_versions.py @@ -0,0 +1,54 @@ +import os +import json +from github import Github + +def update_latest_versions(): + version = os.environ["GITHUB_REF"].split("/")[-1] + + if "rc" 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, + ) + + try: + pr = repo.create_pull(title="Update latest-versions.json", + body="Automated PR to update the latest-versions.json file.", + head=branch_name, base="dev") + except Exception as e: + print(f"Error while creating PR: {e}") + + pr.create_review_request(reviewers=["ebicoglu", "gizemmutukurt", "skoc10"]) + +if __name__ == "__main__": + should_create_pr = update_latest_versions() + if should_create_pr: + create_pr() diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml new file mode 100644 index 0000000000..b929fa6d3c --- /dev/null +++ b/.github/workflows/publish-release.yml @@ -0,0 +1,44 @@ +name: Create Release + +on: + workflow_dispatch: + inputs: + tag_name: + description: 'Tag Name' + required: true + prerelease: + description: 'Pre-release?' + required: true + branchName: + description: 'Branch Name' + required: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.branchName }} + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} + with: + tag_name: ${{ github.event.inputs.tag_name }} + release_name: ${{ github.event.inputs.tag_name }} + draft: false + prerelease: ${{ github.event.inputs.prerelease }} + + - name: Checkout code at tag + uses: actions/checkout@v2 + with: + ref: ${{ github.event.inputs.tag_name }} + + - name: Build Project + run: | + # add your build commands here, depending on your project's requirements. + echo "Build project here" diff --git a/.github/workflows/update-versions.yml b/.github/workflows/update-versions.yml new file mode 100644 index 0000000000..d0a295884f --- /dev/null +++ b/.github/workflows/update-versions.yml @@ -0,0 +1,33 @@ +name: Update Latest Versions + +on: + release: + types: + - published + +permissions: + contents: write + pull-requests: write + +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.RELEASE_TOKEN }} + run: | + python .github/scripts/update_versions.py