Draft Release #16
This file contains 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: Draft Release | |
on: | |
workflow_dispatch: | |
inputs: | |
push_hero: | |
description: The person responsible for facilitating the release. | |
required: true | |
type: choice | |
options: | |
- kevinmind | |
- diox | |
- eviljeff | |
tag: | |
description: 'Release date YYYY.MM.DD Also used to generate the tag name.' | |
required: true | |
jobs: | |
draft_release: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Create Release Draft | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
shell: bash | |
run: | | |
if [ -z "${{ github.event.inputs.tag }}" ]; then | |
echo "Tag is required" | |
exit 1 | |
fi | |
if [ -z "${{ github.event.inputs.push_hero }}" ]; then | |
echo "Push hero is required" | |
exit 1 | |
fi | |
# Format current date as YYYY.MM.DD | |
if [[ "${{ github.event_name}}" == 'workflow_dispatch' ]]; then | |
tag="${{ github.event.inputs.tag }}" | |
fi | |
# Validate the tag is formatted correctly YYYY.MM.DD or YYYY.MM.DD-X | |
# where X is a whole number greater than zero | |
if [[ ! $tag =~ ^[0-9]{4}\.[0-9]{2}\.[0-9]{2}(-[0-9]+)?$ ]]; then | |
echo "Invalid tag format. Must be YYYY.MM.DD or YYYY.MM.DD-X" | |
exit 1 | |
fi | |
# Verify that a release with this tag does not already exist | |
if gh release view $tag &> /dev/null; then | |
echo "Release $tag-next already exists" | |
exit 1 | |
fi | |
# Get the latest release tag | |
previous_release=$( | |
gh api \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/mozilla/addons-server/releases/latest | |
) | |
previous_tag=$(echo $previous_release | jq -r '.tag_name') | |
previous_release_url=$(echo $previous_release | jq -r '.html_url') | |
cat <<EOF | |
$previous_release | |
EOF | |
# Cat the file ../release-template.md | |
template=$(cat .github/release-template.md) | |
# Replace {{GITHUB_USER}} in template with ${{ github.event.inputs.push_hero }} | |
template=${template//\{\{GITHUB_USER\}\}/${{ github.event.inputs.push_hero }}} | |
# Replace {{PREVIOUS_TAG}} in template with $previous_tag | |
template=${template//\{\{PREVIOUS_TAG\}\}/$previous_tag} | |
# Replace {{PREVIOUS_RELEASE_URL}} in template with $previous_release_url | |
template=${template//\{\{PREVIOUS_RELEASE_URL\}\}/$previous_release_url} | |
gh release create $tag \ | |
--title $tag \ | |
--target master \ | |
--notes "$template" \ | |
--draft |