Auto update cromwell-helm chart version to 0.2.548 and coa-helm chart… #1345
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: update-and-publish-cromwell-helm-chart | |
on: | |
push: | |
branches: | |
- 'main' | |
jobs: | |
update-and-publish: | |
name: Update and publish new cromwell-helm chart | |
runs-on: ubuntu-latest | |
steps: | |
- name: Ensure that a Jira ID is present in the commit message | |
id: ensure-jira-id | |
run: | | |
JIRA_ID=$(echo '${{ github.event.head_commit.message }}' | grep -Eo '\[?[A-Z][A-Z]+-[0-9]+\]?') | |
[[ -z "$JIRA_ID" ]] && { echo "No Jira ID found in $1" ; exit 1; } | |
echo ::set-output name=JIRA_ID::${JIRA_ID} | |
- name: Check out the repository | |
uses: actions/checkout@v2 | |
with: | |
token: ${{ secrets.BROADBOT_TOKEN }} # Has to be set at checkout AND later when pushing to work | |
- name: Find out next chart version | |
run: | | |
currentVersionGCP=$(grep '^version:' cromwell-helm/Chart.yaml | awk '{print $NF}') | |
currentVersionCOA=$(grep '^version:' coa-helm/Chart.yaml | awk '{print $NF}') | |
# this will increment only the patch version digit. For example, it will update 0.1.10 => 0.1.11 | |
nextVersionGCP=$(echo ${currentVersionGCP} | awk -F. -v OFS=. '{$NF += 1 ; print}') | |
nextVersionCOA=$(echo ${currentVersionGCP} | awk -F. -v OFS=. '{$NF += 1 ; print}') | |
echo "CURRENT_VERSION_GCP=$currentVersionGCP" >> $GITHUB_ENV | |
echo "NEXT_VERSION_GCP=$nextVersionGCP" >> $GITHUB_ENV | |
echo "CURRENT_VERSION_COA=$currentVersionCOA" >> $GITHUB_ENV | |
echo "NEXT_VERSION_COA=$nextVersionCOA" >> $GITHUB_ENV | |
- name: Bump chart version | |
run: | | |
sed -i "s/$CURRENT_VERSION_GCP/$NEXT_VERSION_GCP/" cromwell-helm/Chart.yaml | |
sed -i "s/$CURRENT_VERSION_COA/$NEXT_VERSION_COA/" coa-helm/Chart.yaml | |
- name: Publish the new helm chart and update index.yaml | |
run: | | |
helm dependency update cromwell-helm/ | |
helm package cromwell-helm/ | |
mv cromwell-${NEXT_VERSION_GCP}.tgz charts/cromwell-${NEXT_VERSION_GCP}.tgz | |
helm dependency update coa-helm/ | |
helm package coa-helm/ | |
mv cromwell-on-azure-${NEXT_VERSION_COA}.tgz charts/cromwell-on-azure-${NEXT_VERSION_COA}.tgz | |
helm repo index --url https://broadinstitute.github.io/cromwhelm/charts/ charts | |
- name: Push changes to GitHub | |
env: | |
BROADBOT_TOKEN: ${{ secrets.BROADBOT_TOKEN }} | |
run: | | |
git checkout main | |
git diff | |
git add . | |
git config --global user.name "broadbot" | |
git config --global user.email "[email protected]" | |
git commit -am "Auto update cromwell-helm chart version to $NEXT_VERSION_GCP and coa-helm chart version to $NEXT_VERSION_COA" | |
git push https://broadbot:[email protected]/broadinstitute/cromwhelm.git main | |
- name: Find out latest chart version from cromwhelm repository | |
run: | | |
function getLatestChartVersion(){ | |
# A function for extracting the highest chart version from those in the input directory. | |
ls $1 | # list the input directory contents. | |
grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' | # extract semantic versions from filenames. | |
sort -V | # sort the resulting versions with -V, in ascending order. | |
tail -1 # get the last (highest) version. | |
} | |
NEW_CROMWELL_HELM_V=$(getLatestChartVersion charts) | |
echo "NEW_CROMWELL_HELM_V=${NEW_CROMWELL_HELM_V}" >> $GITHUB_ENV | |
if [ "${NEW_CROMWELL_HELM_V}" != "${NEXT_VERSION_COA}" ]; then | |
echo "New version ${NEW_CROMWELL_HELM_V} does not match CoA version ${NEXT_VERSION_COA}" | |
exit 1 | |
fi | |
if [ "${NEW_CROMWELL_HELM_V}" != "${NEXT_VERSION_GCP}" ]; then | |
echo "New version ${NEW_CROMWELL_HELM_V} does not match GCP version ${NEXT_VERSION_GCP}" | |
exit 1 | |
fi | |
- name: Clone leonardo | |
uses: actions/checkout@v2 | |
with: | |
repository: broadinstitute/leonardo | |
token: ${{ secrets.BROADBOT_TOKEN }} # Has to be set at checkout AND later when pushing to work | |
path: leonardo | |
- name: Update & push to leonardo | |
id: update-and-push | |
env: | |
BROADBOT_TOKEN: ${{ secrets.BROADBOT_TOKEN }} | |
run: | | |
function getVersionFromReference(){ | |
# A function for extracting the current chart version from Leonardo's reference.conf | |
cat $1 | # print the contents of input file (reference.conf). | |
sed -e '/cromwellApp/,/chartVersion/!d' -e 's:^[ ]*::' | | |
# delete | |
# (1) everything that isn't between these two strings | |
# (2) each line's leading whitespace | |
tail -1 | # get the last line of the resulting text. | |
awk -F'"' '{print $2}' # extract the version number from between the quotes. | |
} | |
function getVersionFromDocker(){ | |
# A function for extracting the current chart version from Leonardo's Dockerfile | |
grep "ENV CROMWELL_CHART_VERSION" $1 | # search for the line where the chart version is set. | |
awk -F'[ ]' '{ print $3 }' # print the third whitespace-separated word (the version). | |
} | |
cd leonardo | |
versionFromReference=$(getVersionFromReference http/src/main/resources/reference.conf) | |
versionFromDocker=$(getVersionFromDocker Dockerfile) | |
if [ $versionFromReference != $versionFromDocker ]; then | |
echo "ERROR: Cromwell versions in reference.conf and Dockerfile do not match." \ | |
"($versionFromReference != $versionFromDocker)" \ | |
exit 1 | |
fi | |
OLD_CROMWELL_HELM_V=$versionFromReference | |
NEW_BRANCH_NAME="cromwell_helm_${NEW_CROMWELL_HELM_V}-AUTOMERGE" | |
TEMP=$(mktemp) | |
git fetch | |
git checkout -b "${NEW_BRANCH_NAME}" | |
SED_STRING="s/${versionFromReference}/${NEW_CROMWELL_HELM_V}/g" | |
FILES=( "Dockerfile" "http/src/main/resources/reference.conf" "http/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/http/ConfigReaderSpec.scala" "http/src/test/scala/org/broadinstitute/dsde/workbench/leonardo/KubernetesTestData.scala" ) | |
for i in "${FILES[@]}" | |
do | |
echo "Updating ${i}" | |
sed "${SED_STRING}" ${i} > ${TEMP} | |
mv ${TEMP} ${i} | |
git add ${i} | |
done | |
echo "Pushing to leonardo branch ${NEW_BRANCH_NAME}" | |
git config --global user.name "broadbot" | |
git config --global user.email "[email protected]" | |
git commit -m "Auto-update Cromwell version to ${NEW_CROMWELL_HELM_V}" | |
git push https://broadbot:[email protected]/broadinstitute/leonardo.git ${NEW_BRANCH_NAME} | |
echo ::set-output name=NEW_BRANCH_NAME::${NEW_BRANCH_NAME} | |
echo ::set-output name=OLD_CROMWELL_HELM_V::${OLD_CROMWELL_HELM_V} | |
echo ::set-output name=NEW_CROMWELL_HELM_V::${NEW_CROMWELL_HELM_V} | |
- name: Create leonardo PR | |
id: create-leo-pr | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.BROADBOT_TOKEN }} | |
script: | | |
const pull_response = await github.rest.pulls.create({ | |
title: '${{ steps.ensure-jira-id.outputs.JIRA_ID }}: Update Cromwell version to ${{ steps.update-and-push.outputs.NEW_CROMWELL_HELM_V }}', | |
owner: 'broadinstitute', | |
repo: 'leonardo', | |
head: '${{ steps.update-and-push.outputs.NEW_BRANCH_NAME }}', | |
base: 'develop', | |
body: [ | |
'This PR is auto-generated by', | |
'[Cromwhelm actions/make_leo_pr](https://github.com/broadinstitute/cromwhelm/blob/main/.github/workflows/make_leo_pr.yml), using', | |
'[github actions/github-script](https://github.com/actions/github-script).', | |
'', | |
'It updates cromwell-helm from version ${{ steps.update-and-push.outputs.OLD_CROMWELL_HELM_V }} to ${{ steps.update-and-push.outputs.NEW_CROMWELL_HELM_V }}.' | |
].join('\n') | |
}); | |
const label_response = github.rest.issues.addLabels({ | |
owner: 'broadinstitute', | |
repo: 'leonardo', | |
issue_number: pull_response.data.number, | |
labels: ['automerge'] | |
}); | |