-
Notifications
You must be signed in to change notification settings - Fork 8
146 lines (114 loc) · 5.78 KB
/
bamboo-compatibility-check.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: 'Bamboo compatibility update check'
on:
schedule:
# Monday 8am AEST (Sunday 10pm UTC)
- cron: '0 22 * * 0'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
GH_TOKEN: ${{ secrets.BAMBOO_GITHUB_ACTIONS_TOKEN }}
GITHUB_TOKEN: ${{ secrets.BAMBOO_GITHUB_ACTIONS_TOKEN }}
jobs:
check-for-update:
name: 'Check if new version of Bamboo has been released'
runs-on: 'ubuntu-latest'
outputs:
current-compatible-version: ${{ steps.version-check.outputs.current-compatible-version }}
latest-bamboo-version: ${{ steps.version-check.outputs.latest-bamboo-version }}
steps:
- uses: actions/checkout@v4
- name: 'Check for new version of Bamboo'
id: version-check
run: |
# get the version our plugin is compatible with
currentCompatibleVersion=$(curl -sS -X GET https://marketplace.atlassian.com/rest/2/addons/com.octopus.bamboo/versions/latest | jq -r '.compatibilities[0].hosting.server.max.version')
# get latest available version of Bamboo
latestBambooVersion=$(curl -sS -X GET https://marketplace.atlassian.com/rest/2/products/key/bamboo/versions/latest | jq -r '.name')
if [ "$currentCompatibleVersion" == "$latestBambooVersion" ]
then
# no update required, bail out of workflow run early
echo "No update required, cancelling this run"
gh run cancel ${{ github.run_id }}
fi
echo "current-compatible-version=$currentCompatibleVersion" >> $GITHUB_OUTPUT
echo "latest-bamboo-version=$latestBambooVersion" >> $GITHUB_OUTPUT
create-issue:
name: 'Create issue'
runs-on: 'ubuntu-latest'
needs: check-for-update
outputs:
gh-issue-url: ${{ steps.create-or-update-issue.outputs.issue-url }}
steps:
- uses: actions/checkout@v4
- name: 'Create or Update Issue for new Bamboo version'
id: create-or-update-issue
run: |
compatibleBambooVersion=${{ needs.check-for-update.outputs.current-compatible-version }}
latestBambooVersion=${{ needs.check-for-update.outputs.latest-bamboo-version }}
issueTitle="Add-on Update Request: Support for Bamboo version $latestBambooVersion"
issueBody=$(cat << EOF
## Add-on compatibility update
- **Compatible Bamboo version:** \`$compatibleBambooVersion\`
- **New Bamboo version:** \`$latestBambooVersion\`
EOF
)
existingIssue=$(gh issue list -q 'map(select(.title | startswith("Add-on Update Request:") ) ) | first' --json title,number | jq '.number')
# if there's no existing issue
if [ -z "$existingIssue" ]
then
# create an issue and assign it to @team-integrations-fnm-bot
issueUrl=$(gh issue create --title "$issueTitle" --body "$issueBody" --assignee "@me")
else
# update existing issue with new compatibility details
issueUrl=$(gh issue edit $existingIssue --title "$issueTitle" --body "$issueBody")
fi
echo "issue-url=$issueUrl" >> $GITHUB_OUTPUT
update-pom:
name: 'Update POM.xml'
runs-on: 'ubuntu-latest'
needs: [check-for-update, create-issue]
if: ${{ needs.create-issue.outputs.gh-issue-url != '' }}
outputs:
changes-committed: ${{ steps.commit-pom-update.outputs.changes-committed }}
branch: ${{ steps.commit-pom-update.outputs.branch-name }}
steps:
- uses: actions/checkout@v4
- name: 'Update Bamboo version in POM.xml and commit the changes'
id: commit-pom-update
run: |
bambooVersion="${{ needs.check-for-update.outputs.latest-bamboo-version }}"
branchName="team-integrations-fnm-bot/bamboo-$bambooVersion"
git config --global user.name "team-integrations-fnm-bot"
git config --global user.email "[email protected]"
git checkout -b $branchName
# Update the version in the <bamboo.version> and <bamboo.data.version> properties
sed -i "s/\(^.*<bamboo\(.data\)\?.version>\).*\(<\/bamboo\(.data\)\?.version>.*$\)/\1$bambooVersion\3/g" pom.xml
git add pom.xml
# if no changes were made, just silently exit
git diff-index --quiet HEAD || (git commit -m "fix: update compatible bamboo version" \
&& git push -u origin $branchName \
&& echo "changes-committed=true" >> $GITHUB_OUTPUT \
&& echo "branch-name=$branchName" >> $GITHUB_OUTPUT \
)
create-pull-request:
name: 'Create PR'
runs-on: 'ubuntu-latest'
needs: [check-for-update, create-issue, update-pom]
if: ${{ needs.update-pom.outputs.changes-committed }}
steps:
- uses: actions/checkout@v4
- name: 'Close any existing PR for Bamboo version update'
id: existing-pr-check
run: |
existingPr=$(gh pr list -q 'map(select(.title | startswith("Add compatibility for Bamboo version") ) ) | first' --json title,number | jq '.number')
if [ "$existingPr" ]
then
# existing pr is for a different Bamboo version, closing existing pr and a new pr will be created
gh pr close $existingPr --comment "Closing PR in favor of new PR for Bamboo version ${{ needs.check-for-update.outputs.bamboo-version }}" --delete-branch
fi
- name: 'Create PR to update Bamboo version in POM.xml'
run: |
title="Add compatibility for Bamboo version ${{ needs.check-for-update.outputs.latest-bamboo-version }}"
body="Fixes ${{ needs.create-issue.outputs.gh-issue-url }}"
head="${{ needs.update-pom.outputs.branch }}"
gh pr create --title "$title" --body "$body" --base "${{ github.ref }}" --head "$head"