From 125106bc68ba9f42290c1afd94b34ca9741cafbf Mon Sep 17 00:00:00 2001 From: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Thu, 18 Dec 2025 23:02:13 -0500 Subject: [PATCH] fix milestone action Now closes properly --- .github/workflows/milestone.yml | 76 +++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/.github/workflows/milestone.yml b/.github/workflows/milestone.yml index 34d4b18..b201c28 100644 --- a/.github/workflows/milestone.yml +++ b/.github/workflows/milestone.yml @@ -1,44 +1,56 @@ -# Trigger the workflow when a release is published name: Close Milestone on Release - on: release: types: [published] - + workflow_dispatch: + inputs: + milestone_tag: + description: 'Specify Release Tag (e.g., v1.2.3). Leave empty for LATEST.' + required: false + default: '' jobs: close_milestone: - # Use the latest Ubuntu runner runs-on: ubuntu-latest - # We only want to proceed if the release tag matches the milestone title + permissions: + issues: write + contents: read steps: - - name: Extract Milestone Title - id: extract + - name: Determine Target Release Tag + id: determine_tag + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - RELEASE_TAG="${{ github.event.release.tag_name }}" + if [[ "${{ github.event_name }}" == "release" ]]; then + RELEASE_TAG="${{ github.event.release.tag_name }}" + elif [[ -n "${{ github.event.inputs.milestone_tag }}" ]]; then + RELEASE_TAG="${{ github.event.inputs.milestone_tag }}" + else + RELEASE_TAG=$(gh api repos/${{ github.repository }}/releases/latest --jq '.tag_name') + fi + # Strip 'v' prefix MILESTONE_TITLE="${RELEASE_TAG#v}" echo "MILESTONE_TITLE=$MILESTONE_TITLE" >> $GITHUB_OUTPUT - + echo "Targeting Milestone: $MILESTONE_TITLE" - name: Close Corresponding Milestone - uses: cli/cli-action@v2 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - args: | - # Search for an open milestone with a title matching the release tag - MILESTONE_ID=$(gh api \ - -H "Accept: application/vnd.github+json" \ - /repos/${{ github.repository }}/milestones \ - -f state='open' \ - -f sort='due_on' \ - -f direction='asc' \ - -f per_page='100' \ - --jq '.[] | select(.title=="${{ steps.extract.outputs.MILESTONE_TITLE }}") | .number' \ - | head -n 1) - if [ -z "$MILESTONE_ID" ]; then - echo "No open milestone found" - else - gh api \ - --method PATCH \ - -H "Accept: application/vnd.github+json" \ - /repos/${{ github.repository }}/milestones/$MILESTONE_ID \ - -f state='closed' - fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + TITLE="${{ steps.determine_tag.outputs.MILESTONE_TITLE }}" + + # Find the milestone by title + MILESTONE_NUMBER=$(gh api repos/${{ github.repository }}/milestones \ + --jq ".[] | select(.title == \"$TITLE\") | .number") + + if [[ -z "$MILESTONE_NUMBER" ]]; then + echo "❌ Milestone '$TITLE' not found" + exit 1 + fi + + echo "Found milestone #$MILESTONE_NUMBER with title '$TITLE'" + + # Close the milestone + gh api repos/${{ github.repository }}/milestones/$MILESTONE_NUMBER \ + -X PATCH \ + -f state=closed + + echo "✅ Successfully closed milestone '$TITLE'"