Skip to content

Bamboo compatibility update check #11

Bamboo compatibility update check

Bamboo compatibility update check #11

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"