From 69f10f21bb5eebb67d1de435db4344c1cdd588da Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Tue, 10 Dec 2024 09:50:52 +0800 Subject: [PATCH 1/3] ci: add scripts to update version number --- .github/workflows/build-on-release.yml | 2 +- update-version.py | 86 ++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 update-version.py diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index fae1e67..da6afeb 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -17,7 +17,7 @@ jobs: with: repository: metabase/metabase path: ${{ github.workspace }}/metabase - ref: release-x.50.x + ref: release-x.52.x - name: install java uses: actions/setup-java@v4 with: diff --git a/update-version.py b/update-version.py new file mode 100644 index 0000000..2974c98 --- /dev/null +++ b/update-version.py @@ -0,0 +1,86 @@ +import re +import sys +import requests + +def get_git_sha(repo, tag): + url = f"https://api.github.com/repos/{repo}/git/refs/tags/{tag}" + response = requests.get(url) + if response.status_code != 200: + raise Exception(f"Failed to get Git SHA for tag {tag}: {response.status_code}") + data = response.json() + return data['object']['sha'][:7] + +def update_yaml_file(yaml_file, version): + # Extract the minor version from the input version + minor_version = version.split('.')[1] + + # Read the YAML file + with open(yaml_file, 'r') as file: + content = file.read() + + # Replace the line with the new minor version + updated_content = re.sub( + r'ref: release-x\.\d+\.x', + f'ref: release-x.{minor_version}.x', + content + ) + + # Write the updated content back to the YAML file + with open(yaml_file, 'w') as file: + file.write(updated_content) + +def update_dockerfile(dockerfile, version): + # Read the Dockerfile + with open(dockerfile, 'r') as file: + content = file.read() + + # Replace the old version number with the new one + updated_content = re.sub( + r'v\d+\.\d+\.\d+(\.\d+)?', + version, + content + ) + + # Write the updated content back to the Dockerfile + with open(dockerfile, 'w') as file: + file.write(updated_content) + +def update_deps_edn(deps_file, version, git_sha): + # Read the last file + with open(deps_file, 'r') as file: + content = file.read() + + # Replace the old version number with the new one + updated_content = re.sub( + r'v\d+\.\d+\.\d+(\.\d+)?', + version, + content + ) + + # Replace the old Git SHA with the new one + updated_content = re.sub( + r'[a-f0-9]{7,40}', + git_sha, + updated_content + ) + + # Write the updated content back to the last file + with open(deps_file, 'w') as file: + file.write(updated_content) + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: python update_yaml.py ") + sys.exit(1) + + version = sys.argv[1] + + yaml_files = ['.github/workflows/ci.yml', '.github/workflows/build-on-release.yml'] + for yaml_file in yaml_files: + update_yaml_file(yaml_file, version) + update_dockerfile('docker/Dockerfile', version) + + git_sha = get_git_sha('metabase/metabase', version) + update_deps_edn('deps.edn', version, git_sha) + + print(f"Updated project with version {version}") From 0423c6f72092e3ed7ed760c38280fdf9c37e097c Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Tue, 10 Dec 2024 10:04:14 +0800 Subject: [PATCH 2/3] ci: add ci task --- .github/workflows/update-metabase.yml | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/update-metabase.yml diff --git a/.github/workflows/update-metabase.yml b/.github/workflows/update-metabase.yml new file mode 100644 index 0000000..96f35fc --- /dev/null +++ b/.github/workflows/update-metabase.yml @@ -0,0 +1,52 @@ +name: Update Metabase Version + +on: + schedule: + - cron: '0 4 * * 0' + +jobs: + update_metabase: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - 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 requests + + - name: Get latest Metabase release version + id: get_version + run: | + LATEST_RELEASE=$(curl -s https://api.github.com/repos/metabase/metabase/releases/latest | jq -r .tag_name) + echo "::set-output name=version::$LATEST_RELEASE" + + - name: Run update_files.py + run: | + python update-version.py ${{ steps.get_version.outputs.version }} + + - name: Check if workspace is dirty + id: check_dirty + run: | + if [[ -n $(git status --porcelain) ]]; then + echo "::set-output name=is_dirty::true" + else + echo "::set-output name=is_dirty::false" + fi + + - name: Create pull request if workspace is dirty + if: steps.check_dirty.outputs.is_dirty == 'true' + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.PAT }} + commit-message: "Update Metabase to ${{ steps.get_version.outputs.version }}" + title: "Update Metabase to ${{ steps.get_version.outputs.version }}" + body: "This PR updates the Metabase version to ${{ steps.get_version.outputs.version }}." + branch: update-metabase-${{ steps.get_version.outputs.version }} From 3f398dd06443b778e51ba381f13c204a0c4869d7 Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Tue, 10 Dec 2024 10:05:05 +0800 Subject: [PATCH 3/3] ci: trigger the tasks manually --- .github/workflows/update-metabase.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/update-metabase.yml b/.github/workflows/update-metabase.yml index 96f35fc..da8801d 100644 --- a/.github/workflows/update-metabase.yml +++ b/.github/workflows/update-metabase.yml @@ -3,6 +3,7 @@ name: Update Metabase Version on: schedule: - cron: '0 4 * * 0' + workflow_dispatch: jobs: update_metabase: