Skip to content

Draft Release

Draft Release #75

Workflow file for this run

name: Draft Release
on:
workflow_dispatch:
inputs:
push_hero:
description: The person responsible for facilitating the release.
required: true
type: choice
options:
- diox
- eviljeff
tag:
description: 'Release date YYYY.MM.DD Also used to generate the tag name.'
required: true
permissions: {}
jobs:
draft_release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- name: Create Release Draft
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.inputs.tag }}
push_hero: ${{ github.event.inputs.push_hero }}
event_name: ${{ github.event_name }}
shell: bash
run: |
if [ -z "$tag" ]; then
echo "Tag is required"
exit 1
fi
if [ -z "$push_hero" ]; then
echo "Push hero is required"
exit 1
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 <push_hero>
template=${template//\{\{GITHUB_USER\}\}/$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