-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from GreptimeTeam/ci/update-metabase
ci: add scripts to update version number
- Loading branch information
Showing
3 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |