Skip to content

Commit

Permalink
add workflows for creating issue/pr if update on polkadot
Browse files Browse the repository at this point in the history
  • Loading branch information
hitchhooker committed Feb 26, 2024
1 parent 511c6a1 commit 3623163
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/polkadot_version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Check Polkadot and Cumulus Update

Check failure on line 1 in .github/workflows/polkadot_version.yaml

View workflow job for this annotation

GitHub Actions / build (3.10)

yaml[document-start]

Missing document start "---"

on:
schedule:
- cron: '0 0 * * *' # Runs at midnight UTC every day

Check failure on line 5 in .github/workflows/polkadot_version.yaml

View workflow job for this annotation

GitHub Actions / build (3.10)

yaml[comments]

Too few spaces before comment

jobs:
update-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository

Check failure on line 11 in .github/workflows/polkadot_version.yaml

View workflow job for this annotation

GitHub Actions / build (3.10)

yaml[indentation]

Wrong indentation: expected 6 but found 4
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"
2 changes: 1 addition & 1 deletion group_vars/cumulus.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
default_client_name: polkadot-v
default_client_version: 1.7.0
default_client_version: 1.7.1
default_download_base_url: "https://github.com/paritytech/polkadot-sdk/releases/download/"
default_download_url: "{{ default_download_base_url }}{{ default_client_name }}{{ default_client_version }}/polkadot-parachain"

Expand Down
1 change: 0 additions & 1 deletion host_vars/pso16.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ default_telemetry_name: "Rotko Networks - {{ host_name.split('.')[0] }} {{ defau
default_public_dns: "{{ host_name }}"
default_network: "paseo"
default_chain_spec: "{{ default_base_path }}/paseo.raw.json"
#default_chain_spec_dl_url: "https://raw.githubusercontent.com/paseo-network/runtimes/8cb10b1404f3e1ec79aa72f88d182f6a3f38b3a3/chain-specs/paseo.raw.json"
# default_chain_spec_dl_url: "https://raw.githubusercontent.com/paseo-network/runtimes/main/chain-specs/paseo.raw.json"
default_chain_spec_dl_url: "https://raw.githubusercontent.com/paseo-network/runtimes/fixed-chain-spec/chain-specs/paseo.raw.json"
default_database: paritydb
Expand Down
39 changes: 39 additions & 0 deletions scripts/extract_version.py
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.")

0 comments on commit 3623163

Please sign in to comment.