From 80b7b86176aaec18cb30f96bd301a897a2703c07 Mon Sep 17 00:00:00 2001 From: leslieber <118453717+leslieber@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:51:18 +0200 Subject: [PATCH] Automate tool version update ptdata 958 test (#462) * 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] --------- 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/workflows/ToolUpdate.yml | 85 +++++++++++++++++++ .github/workflows/main.yml | 4 +- .../update-compile-and-validation-tools.py | 30 +++++++ 3 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ToolUpdate.yml create mode 100644 scripts/update-compile-and-validation-tools.py diff --git a/.github/workflows/ToolUpdate.yml b/.github/workflows/ToolUpdate.yml new file mode 100644 index 00000000..1e629d66 --- /dev/null +++ b/.github/workflows/ToolUpdate.yml @@ -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}`); \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index aed4250f..5d2438a4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 @@ -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 diff --git a/scripts/update-compile-and-validation-tools.py b/scripts/update-compile-and-validation-tools.py new file mode 100644 index 00000000..e2ce5b6e --- /dev/null +++ b/scripts/update-compile-and-validation-tools.py @@ -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}") \ No newline at end of file