-
Notifications
You must be signed in to change notification settings - Fork 1
120 lines (104 loc) · 5.02 KB
/
ToolUpdate.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Update Dependency
on: # Trigger on commits to any branch and manual trigger
workflow_dispatch: # Allows manual trigger
push:
paths:
- 'Resources/**'
branches-ignore:
- 'main**'
pull_request:
branches:
- 'main**'
schedule:
- cron: '0 0 * * *' # Runs at 00:00 UTC every day
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
- name: Check if Firely version is up-to-date
id: check_firely_version
run: |
CURRENT_VERSION_FIRELY=$(grep -oP 'FirelyTeam/firely-terminal-pipeline@\K[^"]+' .github/workflows/main.yml)
if [ "$CURRENT_VERSION_FIRELY" = "$LATEST_VERSION_FIRELY" ]; then
echo "Firely version is up-to-date"
echo "update_needed=false" >> $GITHUB_ENV
else
echo "update_needed=true" >> $GITHUB_ENV
fi
- name: Check if Sushi version is up-to-date
id: check_sushi_version
run: |
CURRENT_VERSION_SUSHI=$(grep -oP 'SUSHI_VERSION: \K[^"]+' .github/workflows/main.yml)
if [ "$CURRENT_VERSION_SUSHI" = "$LATEST_VERSION_SUSHI" ]; then
echo "Sushi version is up-to-date"
echo "update_needed=false" >> $GITHUB_ENV
else
echo "update_needed=true" >> $GITHUB_ENV
fi
- name: Stop if no update is needed
if: env.update_needed == 'false'
continue-on-error: false
run: |
echo "No update needed. Exiting."
exit 0
- 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}`);