Skip to content

Commit

Permalink
Merge pull request #7 from GreptimeTeam/ci/update-metabase
Browse files Browse the repository at this point in the history
ci: add scripts to update version number
  • Loading branch information
sunng87 authored Dec 10, 2024
2 parents 9516ada + 3f398dd commit 861a806
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/build-on-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/update-metabase.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Update Metabase Version

on:
schedule:
- cron: '0 4 * * 0'
workflow_dispatch:

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 }}
86 changes: 86 additions & 0 deletions update-version.py
Original file line number Diff line number Diff line change
@@ -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 <version>")
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}")

0 comments on commit 861a806

Please sign in to comment.