Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Project Automation Workflows #32667

Merged
merged 6 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .ci/scripts/archive-on-milestone-closed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

PROJECT_NUMBER=196
PROJECT_ID="PVT_kwDOAAuecM4AF-7h"

main () {
ISSUES=$(gh api graphql --paginate -F milestone="$MILESTONE" -f query='
query($milestone: Int!, $endCursor: String) {
organization(login: "hashicorp") {
repository(name: "terraform-provider-aws") {
milestone(number: $milestone) {
issues(first: 10, after: $endCursor) {
edges {
node {
id
projectItems(includeArchived: false, first: 10) {
nodes {
id
project {
id
}
}
}
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
}
}' --jq '.data.organization.repository.milestone.issues.edges[].node.projectItems.nodes[]' | jq --slurp '. | tojson')

PULLS=$(gh api graphql --paginate -F milestone="$MILESTONE" -f query='
query($milestone: Int!, $endCursor: String) {
organization(login: "hashicorp") {
repository(name: "terraform-provider-aws") {
milestone(number: $milestone) {
pullRequests(first: 10, after: $endCursor) {
edges {
node {
id
projectItems(includeArchived: false, first: 10) {
nodes {
id
project {
id
}
}
}
}
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
}
}' --jq '.data.organization.repository.milestone.pullRequests.edges[].node.projectItems.nodes[]' | jq --slurp '. | tojson')

PROJECT_ITEMS=$(jq \
--null-input \
--arg project "$PROJECT_ID" \
--argjson issues "$ISSUES" \
--argjson pulls "$PULLS" \
'$issues, $pulls | fromjson | .[] | select(.project.id == $project).id')

for item in $PROJECT_ITEMS; do
echo "Archiving $item"
gh project item-archive "$PROJECT_NUMBER" --owner "hashicorp" --id "$item"
done
}

main
38 changes: 38 additions & 0 deletions .github/workflows/issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,44 @@ jobs:
enable-versioned-regex: 0
include-title: 1

add_to_project:
name: 'Add to Project'
runs-on: ubuntu-latest
needs: community_check
env:
GH_TOKEN: ${{ secrets.PROJECT_SCOPED_TOKEN }}
# Some gh project calls take the project's ID, some take the project's number
PROJECT_ID: "PVT_kwDOAAuecM4AF-7h"
PROJECT_NUMBER: "196"
STATUS_FIELD_ID: "PVTSSF_lADOAAuecM4AF-7hzgDcsQA"
VIEW_FIELD_ID: "PVTSSF_lADOAAuecM4AF-7hzgMRB34"
ITEM_URL: ${{ github.event.issue.html_url }}
steps:
- name: 'Maintainer Issues'
if: github.event.action == 'opened' && needs.community_check.outputs.maintainer == 'true'
run: |
PROJECT_ITEM_ID=$(gh project item-add ${{ env.PROJECT_NUMBER }} --owner "hashicorp" --url ${{ env.ITEM_URL }})
gh project item-edit --id "$PROJECT_ITEM_ID" --project-id ${{ env.PROJECT_ID }} --field-id ${{ env.VIEW_FIELD_ID }} --single-select-option-id ${{ vars.team_project_view_working_board }}

- name: 'Assigned to Maintainer'
if: github.event.action == 'assigned' && needs.community_check.outputs.maintainer == 'true'
run: |
PROJECT_ITEM_ID=$(gh project item-add ${{ env.PROJECT_NUMBER }} --owner "hashicorp" --url ${{ env.ITEM_URL }} | jq '.id')
gh project item-edit --id "$PROJECT_ITEM_ID" --project-id ${{ env.PROJECT_ID }} --field-id ${{ env.STATUS_FIELD_ID }} --single-select-option-id ${{ vars.team_project_status_in_progress }}
gh project item-edit --id "$PROJECT_ITEM_ID" --project-id ${{ env.PROJECT_ID }} --field-id ${{ env.VIEW_FIELD_ID }} --single-select-option-id ${{ vars.team_project_view_working_board }}

- name: 'Labeled Prioritized or Regression'
if: contains(fromJSON('["prioritized", "regression"]'), github.event.label.name)
run: |
PROJECT_ITEM_ID=$(gh project item-add ${{ env.PROJECT_NUMBER }} --owner "hashicorp" --url ${{ env.ITEM_URL }})
gh project item-edit --id "$PROJECT_ITEM_ID" --project-id ${{ env.PROJECT_ID }} --field-id ${{ env.VIEW_FIELD_ID }} --single-select-option-id ${{ vars.team_project_view_working_board }}

- name: 'Labeled Engineering Initiative'
if: github.event.label.name == 'engineering-initiative'
run: |
PROJECT_ITEM_ID=$(gh project item-add ${{ env.PROJECT_NUMBER }} --owner "hashicorp" --url ${{ env.ITEM_URL }})
gh project item-edit --id "$PROJECT_ITEM_ID" --project-id ${{ env.PROJECT_ID }} --field-id ${{ env.VIEW_FIELD_ID }} --single-select-option-id ${{ vars.team_project_view_engineering_initiative }}

community_note:
name: 'Add Community Note'
runs-on: ubuntu-latest
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/milestone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,18 @@ jobs:
- name: 'Remove Label from Issues'
run: |
gh issue edit $(echo ${{ steps.get-issues.outputs.issues }} | jq --raw-output '.') --remove-label prioritized

archive_and_unlabel:
name: 'Archive Project Items on Milestone Closed'
runs-on: ubuntu-latest
env:
MILESTONE: ${{ github.event.milestone.number }}
steps:
- name: 'Checkout Repo'
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- name: 'Archive Project Items'
env:
GH_TOKEN: ${{ secrets.PROJECT_SCOPED_TOKEN }}
shell: bash
run: ./.ci/scripts/archive-on-milestone-closed.sh
42 changes: 0 additions & 42 deletions .github/workflows/new-project-automation.yml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/pull_request_review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Process pull_request_review Events

on:
pull_request_review:
types:
- submitted

jobs:
community_check:
name: 'Community Check'
uses: ./.github/workflows/community-check.yml
secrets: inherit
with:
username: ${{ github.event.review.user.login }}

add_to_project:
name: 'Add to Project'
runs-on: ubuntu-latest
needs: community_check
env:
GH_TOKEN: ${{ secrets.PROJECT_SCOPED_TOKEN }}
# Some gh project calls take the project's ID, some take the project's number
PROJECT_ID: "PVT_kwDOAAuecM4AF-7h"
PROJECT_NUMBER: "196"
STATUS_FIELD_ID: "PVTSSF_lADOAAuecM4AF-7hzgDcsQA"
VIEW_FIELD_ID: "PVTSSF_lADOAAuecM4AF-7hzgMRB34"
ITEM_URL: ${{ github.event.pull_request.html_url }}
steps:
- name: 'Pull Requests Approved By Maintainers'
if: github.event.review.state == 'APPROVED' && needs.community_check.outputs.maintainer == 'true'
run: |
PROJECT_ITEM_ID=$(gh project item-add ${{ env.PROJECT_NUMBER }} --owner "hashicorp" --url ${{ env.ITEM_URL }} | jq '.id')
gh project item-edit --id "$PROJECT_ITEM_ID" --project-id ${{ env.PROJECT_ID }} --field-id ${{ env.STATUS_FIELD_ID }} --single-select-option-id ${{ vars.team_project_status_pending_merge }}
gh project item-edit --id "$PROJECT_ITEM_ID" --project-id ${{ env.PROJECT_ID }} --field-id ${{ env.VIEW_FIELD_ID }} --single-select-option-id ${{ vars.team_project_view_working_board }}
54 changes: 54 additions & 0 deletions .github/workflows/pull_request_target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- edited
- labeled
- opened
- ready_for_review

jobs:
community_check:
Expand Down Expand Up @@ -88,6 +89,59 @@ jobs:
xl_label: 'size/XL'
message_if_xl: ''

add_to_project:
name: 'Add to Project'
runs-on: ubuntu-latest
needs: community_check
env:
GH_TOKEN: ${{ secrets.PROJECT_SCOPED_TOKEN }}
# Some gh project calls take the project's ID, some take the project's number
PROJECT_ID: "PVT_kwDOAAuecM4AF-7h"
PROJECT_NUMBER: "196"
STATUS_FIELD_ID: "PVTSSF_lADOAAuecM4AF-7hzgDcsQA"
VIEW_FIELD_ID: "PVTSSF_lADOAAuecM4AF-7hzgMRB34"
ITEM_URL: ${{ github.event.pull_request.html_url }}
steps:
- name: 'Ready Maintainer Pull Requests'
# This isn't pretty, but it ensures that we don't accidentally set the status on accident
if: contains(fromJSON('["opened", "ready_for_review"]'), github.event.action) && needs.community_check.outputs.maintainer == 'true' && !github.event.pull_request.draft
run: |
# In order to update the item's Status field, we need to capture the project item id from the output
PROJECT_ITEM_ID=$(gh project item-add ${{ env.PROJECT_NUMBER }} --owner "hashicorp" --url ${{ env.ITEM_URL }} | jq '.id')
gh project item-edit --id "$PROJECT_ITEM_ID" --project-id ${{ env.PROJECT_ID }} --field-id ${{ env.STATUS_FIELD_ID }} --single-select-option-id ${{ vars.team_project_status_maintainer_pr }}
gh project item-edit --id "$PROJECT_ITEM_ID" --project-id ${{ env.PROJECT_ID }} --field-id ${{ env.VIEW_FIELD_ID }} --single-select-option-id ${{ vars.team_project_view_working_board }}

- name: 'Assigned to Maintainers'
if: github.event.action == 'assigned' && needs.community_check.outputs.maintainer == 'true'
run: |
PROJECT_ITEM_ID=$(gh project item-add ${{ env.PROJECT_NUMBER }} --owner "hashicorp" --url ${{ env.ITEM_URL }} | jq '.id')
gh project item-edit --id "$PROJECT_ITEM_ID" --project-id ${{ env.PROJECT_ID }} --field-id ${{ env.STATUS_FIELD_ID }} --single-select-option-id ${{ vars.team_project_status_in_progress }}
gh project item-edit --id "$PROJECT_ITEM_ID" --project-id ${{ env.PROJECT_ID }} --field-id ${{ env.VIEW_FIELD_ID }} --single-select-option-id ${{ vars.team_project_view_working_board }}

- name: 'Ready Partner Pull Requests'
if: contains(github.event.pull_request.labels.*.name, 'partner') && !github.event.pull_request.draft
run: |
PROJECT_ITEM_ID=$(gh project item-add ${{ env.PROJECT_NUMBER }} --owner "hashicorp" --url ${{ env.ITEM_URL }})
gh project item-edit --id "$PROJECT_ITEM_ID" --project-id ${{ env.PROJECT_ID }} --field-id ${{ env.VIEW_FIELD_ID }} --single-select-option-id ${{ vars.team_project_view_partner_contribution }}

- name: 'Ready External Maintainer Pull Requests'
if: contains(github.event.pull_request.labels.*.name, 'external-maintainer') && !github.event.pull_request.draft
run: |
PROJECT_ITEM_ID=$(gh project item-add ${{ env.PROJECT_NUMBER }} --owner "hashicorp" --url ${{ env.ITEM_URL }})
gh project item-edit --id "$PROJECT_ITEM_ID" --project-id ${{ env.PROJECT_ID }} --field-id ${{ env.VIEW_FIELD_ID }} --single-select-option-id ${{ vars.team_project_view_external_maintainer }}

- name: 'Labeled Prioritized or Regression'
if: contains(fromJSON('["prioritized", "regression"]'), github.event.label.name)
run: |
PROJECT_ITEM_ID=$(gh project item-add ${{ env.PROJECT_NUMBER }} --owner "hashicorp" --url ${{ env.ITEM_URL }})
gh project item-edit --id "$PROJECT_ITEM_ID" --project-id ${{ env.PROJECT_ID }} --field-id ${{ env.VIEW_FIELD_ID }} --single-select-option-id ${{ vars.team_project_view_working_board }}

- name: 'Labeled Engineering Initiative'
if: github.event.label.name == 'engineering-initiative'
run: |
PROJECT_ITEM_ID=$(gh project item-add ${{ env.PROJECT_NUMBER }} --owner "hashicorp" --url ${{ env.ITEM_URL }})
gh project item-edit --id "$PROJECT_ITEM_ID" --project-id ${{ env.PROJECT_ID }} --field-id ${{ env.VIEW_FIELD_ID }} --single-select-option-id ${{ vars.team_project_view_engineering_initiative }}

add_to_milestone:
name: 'Add to Milestone'
if: github.event.action == 'closed' && github.event.pull_request.merged
Expand Down
Loading