[go: up one dir, main page]

Skip to content

Commit

Permalink
Clean up the creation of the chart's GitHub release
Browse files Browse the repository at this point in the history
Signed-off-by: Luke Shumaker <lukeshu@datawire.io>
  • Loading branch information
LukeShu committed Jan 13, 2022
1 parent 6339fea commit 9617f65
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 54 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/promote-ga.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ jobs:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
with:
status: ${{ job.status }}
success_text: 'GitHub release was created: ${{ steps.step-create-gh-release.url }}'
failure_text: 'GitHub release failed'
cancelled_text: 'GitHub release was was cancelled'
success_text: 'Emissary GitHub release was created: ${{ steps.step-create-gh-release.url }}'
failure_text: 'Emissary GitHub release failed'
cancelled_text: 'Emissary GitHub release was was cancelled'
fields: |
[{ "title": "Repository", "value": "${env.GITHUB_REPOSITORY}", "short": true },
{ "title": "Branch", "value": "${env.GITHUB_REF}", "short": true },
Expand Down
36 changes: 35 additions & 1 deletion .github/workflows/publish-chart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.GH_AWS_SECRET_ACCESS_KEY }}
AWS_EC2_METADATA_DISABLED: true
GH_GITHUB_API_KEY: ${{ secrets.GH_GITHUB_API_KEY }}
PUBLISH_GIT_RELEASE: true
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -38,3 +37,38 @@ jobs:
{ "title": "Branch", "value": "${env.GITHUB_REF}", "short": true },
{ "title": "Action URL", "value": "${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}"}
]
chart-create-gh-release:
if: ${{ ! contains(github.ref, '-') }}
runs-on: ubuntu-latest
needs: [chart-publish]
name: "Create GitHub release"
env:
GIT_TOKEN: ${{ secrets.GH_GITHUB_API_KEY }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: "Install Deps"
uses: ./.github/actions/setup-deps
- name: "gh auth login"
run: |
echo "${GIT_TOKEN}" | gh auth login --with-token
- name: Create GitHub release
id: step-create-gh-release
run: |
make release/chart-create-gh-release
- name: Slack notification
if: always()
uses: edge/simple-slack-notify@master
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
with:
status: ${{ job.status }}
success_text: 'Chart GitHub release was created: ${{ steps.step-create-gh-release.url }}'
failure_text: 'Chart GitHub release failed'
cancelled_text: 'Chart GitHub release was was cancelled'
fields: |
[{ "title": "Repository", "value": "${env.GITHUB_REPOSITORY}", "short": true },
{ "title": "Branch", "value": "${env.GITHUB_REF}", "short": true },
{ "title": "Action URL", "value": "${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}"}
]
6 changes: 0 additions & 6 deletions charts/emissary-ingress/RELEASE.tpl

This file was deleted.

1 change: 0 additions & 1 deletion charts/emissary-ingress/RELEASE_TITLE.tpl

This file was deleted.

43 changes: 0 additions & 43 deletions charts/scripts/push_chart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,47 +79,4 @@ if [[ `basename ${chart_dir}` != emissary-ingress ]] ; then
exit 0
fi

if [[ $thisversion =~ ^[0-9]+\.[0-9]+\.[0-9]+(-ea)?$ ]] && [[ -n "${PUBLISH_GIT_RELEASE}" ]]; then
if [[ -z "${GH_GITHUB_API_KEY}" ]] ; then
echo "GH_GITHUB_API_KEY not set"
exit 1
fi
tag="chart/v${thisversion}"
export chart_version_no_v=${thisversion}
title=`envsubst < ${chart_dir}/RELEASE_TITLE.tpl`
repo_full_name="emissary-ingress/emissary"
token="${GH_GITHUB_API_KEY}"
description=`envsubst < ${chart_dir}/RELEASE.tpl | awk '{printf "%s\\\n", $0}'`
in_changelog=false
while IFS= read -r line ; do
if ${in_changelog} ; then
if [[ "${line}" =~ "## v" ]] ; then
break
fi
if [[ -n "${line}" ]] ; then
description="${description}\\n${line}"
fi
fi
if [[ "${line}" =~ "## v${chart_version}" ]] ; then
in_changelog=true
fi

done < ${chart_dir}/CHANGELOG.md

generate_post_data()
{
cat <<EOF
{
"tag_name": "$tag",
"name": "$title",
"body": "${description}",
"draft": false,
"prerelease": false,
"target_commitish": "${GITHUB_REF}"
}
EOF
}
curl --fail -H "Authorization: token ${token}" --data "$(generate_post_data)" "https://api.github.com/repos/$repo_full_name/releases"
fi

exit 0
57 changes: 57 additions & 0 deletions releng/chart-create-gh-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3

import fileinput
import os.path
import sys
from os import getenv

from lib import get_gh_repo, re_ga
from lib.uiutil import run, run_txtcapture

def main() -> int:
chart_version = getenv("CHART_VERSION")
if not (chart_version and chart_version.startswith("v") and re_ga.match(chart_version[1:])):
sys.stderr.write(f'Usage: CHART_VERSION=v7.Y.Z {os.path.basename(sys.argv[0])}\n')
return 2

content_gittag = "chart/{chart_version}"

content_title = f"Emissary Ingress Chart {chart_version[1:]}"

content_body = f"""
## :tada: Emissary Ingress Chart {chart_version[1:]} :tada:
Upgrade Emissary - https://www.getambassador.io/reference/upgrading#helm.html
View changelog - https://github.com/emissary-ingress/emissary/blob/master/charts/emissary-ingress/CHANGELOG.md
---
"""
in_changelog = False
for line in fileinput.FileInput("charts/emissary-ingress/CHANGELOG.md"):
print(f"line={repr(line)}")
if in_changelog:
if line.startswith("## v"):
break
content_body += line
if line == f"## {chart_version}\n":
in_changelog = True
content_body = content_body.strip()

run([
"gh", "release", "create",
"--repo="+get_gh_repo(),
"--title="+content_title,
"--notes="+content_body,
content_gittag])

url = run_txtcapture([
"gh", "release", "view",
"--json=url",
"--jq=.url",
"--repo="+get_gh_repo(),
content_gittag])
print(f'::set-output name=url::{url}')


if __name__ == '__main__':
sys.exit(main())
4 changes: 4 additions & 0 deletions releng/release.mk
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ release/rc/check:
release/ga/create-gh-release:
@$(OSS_HOME)/releng/release-create-github $(VERSIONS_YAML_VER)
.PHONY: release/ga/create-gh-release

release/chart-create-gh-release:
$(OSS_HOME)/releng/chart-create-gh-release
.PHONY: release/chart-create-gh-release

0 comments on commit 9617f65

Please sign in to comment.