Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
112 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
name: Auto set milestone on PR | ||
|
||
on: | ||
pull_request: | ||
types: [opened, closed, labeled] | ||
|
||
env: | ||
QGIS_MAJOR_VERSION: 3 | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# TODO: remove | ||
- name: Dump GitHub context | ||
env: | ||
GITHUB_CONTEXT: ${{ toJson(github) }} | ||
run: echo "$GITHUB_CONTEXT" | ||
|
||
# obfuscate the github token so it can be used on jobs triggered from forks | ||
- name: Clear GH Token | ||
id: token | ||
uses: opengisch/clear-token@v1.0.12 | ||
with: | ||
bot_token_encrypted: ddbdec32940df79f1adf2369b4b10f10b5a66f65 | ||
bot_token_xor_key: a1b2c3d47311f8e29e204f85a81b4df4a44e252c | ||
|
||
# list the tags and milestones | ||
- uses: octokit/graphql-action@v2.x | ||
id: list_tags_milestones | ||
with: | ||
query: | | ||
query list_tags_milestones($owner: String!, $repo: String!) { | ||
repository(owner: $owner, name: $repo) { | ||
refs(refPrefix: "refs/tags/", orderBy: {field: TAG_COMMIT_DATE, direction: DESC}, first: 30) { | ||
edges { | ||
node { | ||
name | ||
} | ||
} | ||
} | ||
milestones(orderBy: {field: CREATED_AT, direction: DESC}, first: 30) { | ||
edges { | ||
node { | ||
title | ||
number | ||
} | ||
} | ||
} | ||
} | ||
} | ||
owner: ${{ github.event.pull_request.base.repo.owner.login }} | ||
repo: ${{ github.event.pull_request.base.repo.name }} | ||
env: | ||
GITHUB_TOKEN: ${{ steps.token.outputs.token }} | ||
|
||
# calculate the milestone and determine if it exists | ||
- name: Get the latest release | ||
id: calculate_milestone | ||
env: | ||
JSON_DATA: ${{ steps.list_tags_milestones.outputs.data }} | ||
BASE_BRANCH: ${{ github.event.pull_request.base.ref }} | ||
run: | | ||
# master => NOTHING, release_3-10 => _10 | ||
MINOR_VERSION=$(echo ${BASE_BRANCH} | sed -r -e 's/^release_[0-9]-([0-9]+)/_\1/;t;d') | ||
echo "MINOR_VERSION: ${MINOR_VERSION}" | ||
MAX_RELEASE=$(echo "${JSON_DATA}" | jq ".repository.refs.edges[].node.name | select( . | test(\"^final-${QGIS_MAJOR_VERSION}${MINOR_VERSION}\") ) | sub(\"^final-${QGIS_MAJOR_VERSION}_(?<m>[0-9]+)_(?<p>.)\"; .m+\".\"+.p) | tonumber" | jq -s '. | max') | ||
echo "MAX_RELEASE: ${MAX_RELEASE}" | ||
MILESTONE_TITLE="${QGIS_MAJOR_VERSION}."$(echo "${MAX_RELEASE} + 0.1 " | bc) | ||
echo "MILESTONE_TITLE: ${MILESTONE_TITLE}" | ||
echo "::set-output name=milestone_title::${MILESTONE_TITLE}" | ||
MILESTONE_NUMBER=$(echo ${JSON_DATA} | jq ".repository.refs.edges[] | select( .node.name == \"${MILESTONE_TITLE}\" ) | .node.number") | ||
echo "MILESTONE_NUMBER: ${MILESTONE_NUMBER}" | ||
echo "::set-output name=milestone_number::${MILESTONE_NUMBER}" | ||
MILESTONE_EXISTS=$([[ -n $echo("${JSON_DATA} | jq ".repository.refs.edges[].node.name | select( . | test(\"^${MILESTONE_TITLE}\") )" ]] && echo "true" || echo "false") | ||
echo "MILESTONE_EXISTS: ${MILESTONE_EXISTS}" | ||
echo "::set-output name=milestone_exists::${MILESTONE_EXISTS}" | ||
# create the milestone if needed | ||
- name: Create milestone | ||
id: create_milestone | ||
if: steps.calculate_milestone.outputs.milestone_exists == false | ||
uses: octokit/request-action@v2.x | ||
with: | ||
route: POST /repos/:owner/:repo/milestones | ||
title: ${{ steps.calculate_milestone.outputs.milestone_title }} | ||
owner: ${{ github.event.pull_request.base.repo.owner.login }} | ||
repo: ${{ github.event.pull_request.base.repo.name }} | ||
env: | ||
GITHUB_TOKEN: ${{ steps.token.outputs.token }} | ||
|
||
- id: compute_milestone | ||
name: compute the milestone number | ||
env: | ||
MILESTONE_NUMBER_EXISTING: ${{ steps.calculate_milestone.outputs.milestone_number }} | ||
MILESTONE_NUMBER_CREATED_JSON: ${{ steps.create_milestone.outputs.data }} | ||
run: | | ||
FINAL_MILESTONE_NUMBER=$([[ -n ${MILESTONE_NUMBER_EXISTING} ]] && echo "${MILESTONE_NUMBER_EXISTING}" || $(echo "${MILESTONE_NUMBER_CREATED_JSON}" | jq '.number' )) | ||
echo "FINAL_MILESTONE_NUMBER: ${FINAL_MILESTONE_NUMBER}" | ||
echo "::set-output name=milestone_number::${FINAL_MILESTONE_NUMBER}" | ||
# update PR with milestone | ||
- name: update PR milestone | ||
uses: octokit/request-action@v2.x | ||
env: | ||
GITHUB_TOKEN: ${{ steps.token.outputs.token }} | ||
with: | ||
route: PATCH /repos/:owner/:repo/pulls/:pull_number | ||
pull_number: ${{ github.event.pull_request.number }} | ||
milestone: ${{ steps.compute_milestone.outputs.milestone_number }} | ||
owner: ${{ github.event.pull_request.base.repo.owner.login }} | ||
repo: ${{ github.event.pull_request.base.repo.name }} |