-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add workflows for creating issue/pr if update on polkadot
- Loading branch information
1 parent
511c6a1
commit 3623163
Showing
4 changed files
with
96 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Check Polkadot and Cumulus Update | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * *' # Runs at midnight UTC every day | ||
|
||
jobs: | ||
update-version: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install Python dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pyyaml requests | ||
- name: Check for updates in Polkadot and replace version if needed | ||
id: check-update-polkadot | ||
run: python scripts/extract_version.py group_vars/polkadot.yaml default_client_version paritytech polkadot true | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Check for updates in Cumulus and replace version if needed | ||
id: check-update-cumulus | ||
run: python scripts/extract_version.py group_vars/cumulus.yaml default_client_version paritytech cumulus true | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up Git config | ||
if: steps.check-update-polkadot.outputs.current_version != steps.check-update-polkadot.outputs.latest_release || steps.check-update-cumulus.outputs.current_version != steps.check-update-cumulus.outputs.latest_release | ||
run: | | ||
git config --global user.name 'github-actions[bot]' | ||
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | ||
- name: Commit updated YAML files | ||
if: steps.check-update-polkadot.outputs.current_version != steps.check-update-polkadot.outputs.latest_release || steps.check-update-cumulus.outputs.current_version != steps.check-update-cumulus.outputs.latest_release | ||
run: | | ||
git add group_vars/polkadot.yaml group_vars/cumulus.yaml | ||
git commit -m "Update Polkadot and Cumulus versions" | ||
git push | ||
- name: Create Pull Request for Polkadot and Cumulus Update | ||
if: steps.check-update-polkadot.outputs.current_version != steps.check-update-polkadot.outputs.latest_release || steps.check-update-cumulus.outputs.current_version != steps.check-update-cumulus.outputs.latest_release | ||
uses: repo-sync/pull-request@v2 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
pr_title: "Update Polkadot and Cumulus versions" | ||
pr_body: "Automatically updated by GitHub Actions." | ||
pr_label: "automated-pr" |
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
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,39 @@ | ||
# extract_version.py | ||
import sys | ||
import requests | ||
import yaml | ||
|
||
def extract_current_version(yaml_file, version_key): | ||
with open(yaml_file, 'r') as file: | ||
data = yaml.safe_load(file) | ||
return data[version_key] | ||
|
||
def replace_version(yaml_file, version_key, new_version): | ||
with open(yaml_file, 'r') as file: | ||
data = yaml.safe_load(file) | ||
data[version_key] = new_version | ||
with open(yaml_file, 'w') as file: | ||
yaml.dump(data, file) | ||
|
||
def get_latest_github_release(owner, repo): | ||
url = f"https://api.github.com/repos/{owner}/{repo}/releases/latest" | ||
response = requests.get(url) | ||
response.raise_for_status() # Ensure to raise an error for a bad response | ||
return response.json()['tag_name'] | ||
|
||
if __name__ == "__main__": | ||
yaml_file = sys.argv[1] | ||
version_key = sys.argv[2] | ||
owner = sys.argv[3] | ||
repo = sys.argv[4] | ||
should_update = sys.argv[5] == 'true' # Expects 'true' or 'false' | ||
|
||
current_version = extract_current_version(yaml_file, version_key) | ||
latest_release = get_latest_github_release(owner, repo) | ||
|
||
print(f"::set-output name=current_version::{current_version}") | ||
print(f"::set-output name=latest_release::{latest_release}") | ||
|
||
if should_update and current_version != latest_release: | ||
replace_version(yaml_file, version_key, latest_release) | ||
print("Version updated.") |