Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(buildDockerAndPublishImage): annotate GitHub release with make show output #834

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
52 changes: 37 additions & 15 deletions vars/buildDockerAndPublishImage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ def makecall(String action, String imageDeployName, String targetOperationSystem
"IMAGE_DEPLOY_NAME=${imageDeployName}"
]) {
sh 'export BUILDX_BUILDER_NAME=buildx-builder; docker buildx use "${BUILDX_BUILDER_NAME}" 2>/dev/null || docker buildx create --use --name="${BUILDX_BUILDER_NAME}"'
sh "make bake-$action"
if (action == 'retrieve-make-show') {
return sh(script: 'make show', returnStdout: true)
} else {
sh "make bake-$action"
}
}
} else {
if (action == 'deploy') {
Expand Down Expand Up @@ -285,20 +289,38 @@ def call(String imageShortName, Map userConfig=[:]) {
]) {
String release = ''
if (isUnix()) {
final String releaseScript = '''
originUrlWithGit="$(git remote get-url origin)"
originUrl="${originUrlWithGit%.git}"
org="$(echo "${originUrl}" | cut -d'/' -f4)"
repository="$(echo "${originUrl}" | cut -d'/' -f5)"
releasesUrl="/repos/${org}/${repository}/releases"
releaseId="$(gh api "${releasesUrl}" | jq -e -r '[ .[] | select(.draft == true and .name == "next").id] | max | select(. != null)')"
if test "${releaseId}" -gt 0
then
gh api -X PATCH -F draft=false -F name="${TAG_NAME}" -F tag_name="${TAG_NAME}" "${releasesUrl}/${releaseId}" > /dev/null
fi
echo "${releaseId}"
'''
release = sh(script: releaseScript, returnStdout: true)
final String makeShowContent = makecall('retrieve-make-show', imageName, operatingSystem, finalConfig.dockerBakeFile, finalConfig.dockerBakeTarget)
withEnv(["MAKE_SHOW_CONTENT=${makeShowContent}"]) {
final String releaseScript = '''
originUrlWithGit="$(git remote get-url origin)"
originUrl="${originUrlWithGit%.git}"
org="$(echo "${originUrl}" | cut -d'/' -f4)"
repository="$(echo "${originUrl}" | cut -d'/' -f5)"
releasesUrl="/repos/${org}/${repository}/releases"
releaseId="$(gh api "${releasesUrl}" | jq -e -r '[ .[] | select(.draft == true and .name == "next").id] | max | select(. != null)')"
if test "${releaseId}" -gt 0
then
body="$(gh api "${releasesUrl}/${releaseId}" | jq -e -r '.body')"
body+='

## :memo: What's in this release

<details>

```yaml
'
body+="$(echo ${MAKE_SHOW_CONTENT} | yq --prettyPrint)"
body+='
```

</details>
'
gh api -X PATCH -F draft=false -F name="${TAG_NAME}" -F tag_name="${TAG_NAME}" -F body="${body}" "${releasesUrl}/${releaseId}" > /dev/null
fi
echo "${releaseId}"
'''
release = sh(script: releaseScript, returnStdout: true)
}
} else {
final String releaseScript = '''
$originUrl = (git remote get-url origin) -replace '\\.git', ''
Expand Down