Skip to content

wip

wip #3

name: Milestone Release Reusable Workflow

Check failure on line 1 in .github/workflows/milestone-release.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/milestone-release.yml

Invalid workflow file

No steps defined in `steps` and no workflow called in `uses` for the following jobs: set-default-branch
# Tag and create a Release for milestone workflow. The repository is tagged
# based on the milestone title which should be in the form YYYY-MM-DD. The
# tag is then <MILESTONE>-rc<X> where X is a milestone build number starting from 1.
# If the new release is a beta release, the tag is <MILESTONE>-beta<X> where X is a
# milestone build number starting from 1 (this happends when merging into develop-YYYY-MM-DD branch).
# The github release is then generated with release notes. The release notes are
# generated from the PR titles.
# Also remove milestone branch protection, delete the milestone branch and set the
# default branch back to master.
# Usage example
# on:
# pull_request:
# types:
# - closed
# branches:
# - master
# - develop-*
# jobs:
# release:
# uses: geoadmin/.github/.github/workflows/milestone-release.yml@master
# secrets: inherit
on:
workflow_call:
secrets:
REPO_ACCESS_TOKEN:
required: true
jobs:
delete-milestone-branch:
name: Delete Milestone Branch Protection
runs-on: ubuntu-latest
if: ${{ startsWith(github.head_ref, 'develop-') }}
steps:
# - name: Install hub tool
# run: |
# sudo apt-get update && sudo apt-get install -y hub
- uses: actions/checkout@v4
- name: Set default branch back to master or to next milestone branch
env:
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
run: |
# Get the next milestone branch name, the jq command will return the second
# branch name in the list of branches matching the pattern develop-YYYY-MM-DD
# The first branch is the current branch, the second one is the next milestone
# branch. If there is no next milestone branch, then jq will return null.
next_milestone_branch=$( \
gh api \
-H "Accept: application/vnd.github+json" \
/repos/${{ github.repository }}/branches \
| jq '. | map(select(.name | test("develop-\\d{4}-\\d{2}-\\d{2}"))) | sort_by(.name) | .[1].name ' -r \
)
echo "next_milestone_branch=${next_milestone_branch}"
if [[ "${next_milestone_branch}" == "null" ]];
then
echo "::notice::Set default branch to \"master\""
gh repo edit ${{ github.repository }} --default-branch master
else
echo "::notice::Set default branch to \"${next_milestone_branch}\""
gh repo edit ${{ github.repository }} --default-branch "${next_milestone_branch}"
fi
- name: Delete Milestone Branch Protection
env:
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
HUB_VERBOSE: 0
run: |
set +e
if response=$(gh api -X DELETE /repos/${{ github.repository }}/branches/${{ github.head_ref }}/protection);
then
set -e
# 200 OK
echo "::notice::Milestone Branch Protection \"${{ github.head_ref }}\" deleted"
else
set -e
# NOT 200 OK
message=$(echo "${response}" | jq --raw-output '.message')
echo "response=${response}"
echo "message=${message}"
if [[ "${message}" == "Branch not protected" ]] || [[ "${message}" == "Branch not found" ]]; then
echo "::notice::Milestone Branch Protection \"${{ github.head_ref }}\" already deleted"
else
echo "::error::Failed to delete branch protection \"${{ github.head_ref }}\": ${message}"
exit 1
fi
fi
- name: Delete Milestone Branch
env:
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
HUB_VERBOSE: 0
run: |
set +e
if response=$(gh api -X DELETE /repos/${{ github.repository }}/git/refs/heads/${{ github.head_ref }});
then
set -e
# 200 OK
echo "::notice::Milestone Branch \"${{ github.head_ref }}\" deleted"
else
set -e
# NOT 200 OK
message=$(echo "${response}" | jq --raw-output '.message')
echo "response=${response}"
echo "message=${message}"
if [[ "${message}" == "Reference does not exist" ]]; then
echo "::notice::Milestone Branch \"${{ github.head_ref }}\" already deleted"
else
echo "::error::Failed to delete milestone branch \"${{ github.head_ref }}\": ${message}"
exit 1
fi
fi
set-default-branch:
# We need to first delete the milestone branch, otherwise it will popup in the next milestone
# branch list below
needs: delete-milestone-branch
name: Set default branch back to master or to next milestone branch
runs-on: ubuntu-latest
if: ${{ startsWith(github.head_ref, 'develop-') }}
steps:
milestone-release:
name: Release Milestone
runs-on: ubuntu-latest
steps:
- name: Check event name
run: |
echo "Event is ${{ github.event_name }}"
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
echo "::error::Milestone Release Workflow can only be used with pull_request event"
exit 1
fi
- name: Checkout code
uses: actions/checkout@v4
- name: Bump Milestone Release Tag
id: tagging-release
if: ${{ github.base_ref == 'master' }}
uses: geoadmin/action-milestone-tag@v1.5.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: '${MILESTONE}-rc${TAG_NUMBER}'
milestone_pattern: '\d{4}-\d{2}-\d{2}'
- name: Bump Milestone Beta Tag
id: tagging-beta
if: ${{ startsWith(github.base_ref, 'develop-') }}
uses: geoadmin/action-milestone-tag@v1.5.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: '${MILESTONE}-beta${TAG_NUMBER}'
milestone_pattern: '\d{4}-\d{2}-\d{2}'
# Drafts your next Release notes as Pull Requests are merged into "master"
- name: Create Release with Release Notes
uses: release-drafter/release-drafter@v6
if: ${{ github.base_ref == 'master' }}
with:
config-name: release-drafter-config.yml
disable-autolabeler: true
publish: true
tag: ${{ steps.tagging-release.outputs.new_tag }}
version: ${{ steps.tagging-release.outputs.new_tag }}
name: ${{ steps.tagging-release.outputs.new_tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Close the milestone if needed
- name: Get milestone name from tag
if: ${{ startsWith(github.head_ref, 'develop-') }}
id: get-milestone
shell: bash
run: |
tag=${{ steps.tagging-release.outputs.new_tag }}
milestone="${tag%%-rc*}"
echo "milestone=${milestone}" >> $GITHUB_OUTPUT
echo "::notice::Milestone is ${milestone}"
- name: Close the milestone if needed
if: ${{ startsWith(github.head_ref, 'develop-') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
milestone=$(gh api /repos/${{ github.repository }}/milestones | \
jq -c '.[] | select(.title=="${{ steps.get-milestone.outputs.milestone }}").number')
echo "::notice::Milestone found \"${milestone}\""
gh api "/repos/${{ github.repository }}/milestones/${milestone}" \
--method "PATCH" \
-f "state=closed"