[datadog-operator] Update Github Workflow for Milestone #1
Workflow file for this run
This file contains hidden or 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: Add Milestone on a Merged PR | |
| on: | |
| pull_request: | |
| types: | |
| - closed | |
| branches: | |
| - main | |
| - "v[0-9]+.[0-9]+" | |
| permissions: {} | |
| jobs: | |
| add-milestone-pr: | |
| name: Add Milestone on PR | |
| if: github.event.pull_request.merged == true | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GH_REPO: ${{ github.repository }} | |
| steps: | |
| - name: Get current milestone from branch | |
| id: current-milestone | |
| run: | | |
| BASE_BRANCH="${{ github.base_ref }}" | |
| if [[ "$BASE_BRANCH" == "main" ]]; then | |
| # For main, use the open milestone with the highest creation order (latest upcoming release). | |
| MILESTONE=$(gh api repos/${{ github.repository }}/milestones \ | |
| --jq '[.[] | select(.state == "open")] | sort_by(.number) | last | .title') | |
| elif [[ "$BASE_BRANCH" =~ ^v([0-9]+)\.([0-9]+)$ ]]; then | |
| # For release branches like v1.25, derive the milestone as v1.25.0. | |
| MILESTONE="v${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.0" | |
| else | |
| echo "Error: Unexpected branch '$BASE_BRANCH'." | |
| exit 1 | |
| fi | |
| if [ -z "$MILESTONE" ]; then | |
| echo "Error: Couldn't determine a current milestone for branch '$BASE_BRANCH'." | |
| exit 1 | |
| fi | |
| if [[ ! $MILESTONE =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "Error: Malformed milestone '$MILESTONE'. It should be of the form 'vX.Y.Z'." | |
| exit 1 | |
| fi | |
| echo "MILESTONE=$MILESTONE" >> "$GITHUB_OUTPUT" | |
| - name: Set the merged PR milestone to current milestone | |
| run: | | |
| echo "Setting milestone $MILESTONE to PR $NUMBER." | |
| gh issue edit "$NUMBER" --milestone "$MILESTONE" | |
| env: | |
| NUMBER: ${{ github.event.number }} | |
| MILESTONE: ${{ steps.current-milestone.outputs.MILESTONE }} |