Skip to content

Commit

Permalink
Automate tool version update ptdata 958 test (#462)
Browse files Browse the repository at this point in the history
* add action

* lower firely action for test purposes

* fix removing feature

* fix update on main.yml

* fix path

* fix path

* fix using force push

* fix: trial set permissions

* fix using PR

* fix variable setting

* fix : try js script instead of action for PR

* update sushi for test

* add test comment

* fix automated

* fix trial

* add python script for updating sushi and firely terminal

* rm pr feature

* fix trial using secret

* fix trial update permision / key

* fix trial

* fix trial

* add notification action

* update warning

* update warning

* fix if statement

* update trigger

* update name of wokflow

* add skipping step

* fix skipping step

* fix trial

* update permission and execute

* update token variables

* fix permissions

* tidy up

* update documentation and todo

* rename script

* fix name

* fix name

* sushi and firely automated update

* Test workflow

* sushi update without v

* Update dependencies to versions Firely: v0.4.2, Sushi: 3.12.0 (#461)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: f-peverali <112709306+f-peverali@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 16, 2024
1 parent d7d0ea5 commit 80b7b86
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 2 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/ToolUpdate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Update Dependency

on: # Trigger on commits to any branch and manual trigger
workflow_dispatch: # Allows manual trigger
push:
branches:
- '**' # Trigger on commits to any branch

permissions:
contents: write
pull-requests: write

jobs:
update-dependency:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
token: ${{ secrets.WORKFLOW_PERMISSION_GITHUB }} # Personal access token with workflow permissions

- name: Set up jq
run: sudo apt-get install jq

- name: Fetch latest version of firely terminal dependency
id: fetch_version_firely
run: |
# Fetch the latest version from the FirelyTeam/firely-terminal-pipeline GitHub repository
LATEST_VERSION_FIRELY=$(curl -s https://api.github.com/repos/FirelyTeam/firely-terminal-pipeline/releases/latest | jq -r .tag_name)
echo "LATEST_VERSION_FIRELY=$LATEST_VERSION_FIRELY" >> $GITHUB_ENV
echo $LATEST_VERSION_FIRELY
- name: Fetch latest version of Sushi dependency
id: fetch_version_sushi
run: |
# Fetch the latest version from the fhir/sushi GitHub repository
LATEST_VERSION_SUSHI=$(curl -s https://api.github.com/repos/FHIR/sushi/releases/latest | jq -r .tag_name | sed 's/^v//')
echo "LATEST_VERSION_SUSHI=$LATEST_VERSION_SUSHI" >> $GITHUB_ENV
echo $LATEST_VERSION_SUSHI
# TODO add an if statement to prevent the workflow from running if the version is the same as the one in the main.yml file


- name: Update main.yml for Firely and Sushi
run: |
# Update the main.yml file with the new versions of Firely and Sushi
sed -i "s|uses: FirelyTeam/firely-terminal-pipeline@.*|uses: FirelyTeam/firely-terminal-pipeline@$LATEST_VERSION_FIRELY|" .github/workflows/main.yml
sed -i "s|SUSHI_VERSION: .*|SUSHI_VERSION: $LATEST_VERSION_SUSHI|" .github/workflows/main.yml
- name: Commit changes
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
# Commit the changes
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git checkout -b update-dependency-${LATEST_VERSION_FIRELY}-${LATEST_VERSION_SUSHI} || git checkout update-dependency-${LATEST_VERSION_FIRELY}-${LATEST_VERSION_SUSHI}
git add .github/workflows/main.yml
git commit -m "Update dependencies to versions Firely: ${LATEST_VERSION_FIRELY}, Sushi: ${LATEST_VERSION_SUSHI}"
git push https://x-access-token:${{ secrets.WORKFLOW_PERMISSION_GITHUB }}@github.com/${{ github.repository }}.git update-dependency-${LATEST_VERSION_FIRELY}-${LATEST_VERSION_SUSHI}
- name: Create Pull Request
uses: actions/github-script@v6
with:
script: |
const latestVersionFirely = process.env.LATEST_VERSION_FIRELY;
const latestVersionSushi = process.env.LATEST_VERSION_SUSHI;
if (!latestVersionFirely || !latestVersionSushi) {
throw new Error('Versions are not defined');
}
const prTitle = `Update dependencies to versions Firely: ${latestVersionFirely}, Sushi: ${latestVersionSushi}`;
const prHead = `update-dependency-${latestVersionFirely}-${latestVersionSushi}`;
const prBody = `This PR updates the dependencies to versions Firely: ${latestVersionFirely} and Sushi: ${latestVersionSushi}.`;
const { data: pullRequest } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: prTitle,
head: prHead,
base: context.ref.replace('refs/heads/', ''),
body: prBody,
maintainer_can_modify: true,
});
console.log(`Created pull request: ${pullRequest.html_url}`);
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
# Java and .NET are already installed on ubuntu-latest

- name: Firely.Terminal (GitHub Actions)
uses: FirelyTeam/firely-terminal-pipeline@v0.4.1
uses: FirelyTeam/firely-terminal-pipeline@v0.4.2
with:
PATH_TO_CONFORMANCE_RESOURCES: Resources/fsh-generated/resources/
#PATH_TO_EXAMPLES: Examples
Expand All @@ -46,7 +46,7 @@ jobs:
SIMPLIFIER_PASSWORD: ${{ secrets.SIMPLIFIER_PASSWORD }}
SUSHI_ENABLED: true
SUSHI_OPTIONS: Resources/
SUSHI_VERSION: 3.8.0
SUSHI_VERSION: 3.12.0
EXPECTED_FAILS: VALIDATION_CONFORMANCE_DOTNET VALIDATION_CONFORMANCE_JAVA VALIDATION_EXAMPLES_JAVA

- name: Add & Commit
Expand Down
30 changes: 30 additions & 0 deletions scripts/update-compile-and-validation-tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
### This script updates the main.yml file with the latest versions of firely-terminal and sushi and can be used locally
import requests
import os

def get_latest_version(repo):
url = f"https://api.github.com/repos/{repo}/releases/latest"
response = requests.get(url)
response.raise_for_status()
return response.json()["tag_name"]

if __name__ == "__main__":
firely_terminal_version = get_latest_version("FirelyTeam/firely-terminal-pipeline")
sushi_version = get_latest_version("FHIR/sushi")

script_dir = os.path.dirname(__file__)
main_yml_path = os.path.abspath(os.path.join(script_dir, "../.github/workflows/main.yml"))

with open(main_yml_path, "r") as file:
lines = file.readlines()

with open(main_yml_path, "w") as file:
for line in lines:
if line.strip().startswith("uses: FirelyTeam/firely-terminal-pipeline@"):
file.write(f" uses: FirelyTeam/firely-terminal-pipeline@{firely_terminal_version}\n")
elif line.strip().startswith("SUSHI_VERSION:"):
file.write(f" SUSHI_VERSION: {sushi_version}\n")
else:
file.write(line)

print(f"Updated main.yml with firely-terminal=={firely_terminal_version} and sushi=={sushi_version}")

0 comments on commit 80b7b86

Please sign in to comment.