-
Notifications
You must be signed in to change notification settings - Fork 7
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
1 parent
44fbe0a
commit b02bdf5
Showing
3 changed files
with
166 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,32 @@ | ||
### Update Project date on issue update | ||
A event automation that updates the tt-forge project date with the last issue date. | ||
|
||
### Testing | ||
##### Manually test has to be done since it diffcult to simulate a GH project at this time. | ||
|
||
Create a branch/fork of this repo and a branch of your desired test repo ex. `tt-milr` | ||
|
||
On the `issue-last-updated.yml`, update the branch reference to your the `tt-github-actions` | ||
```bash | ||
ex. uses: jmcgrathTT/tt-github-actions/.github/actions/${action_name}@${your_tt_github_actions_branch_name} | ||
uses: jmcgrathTT/tt-github-actions/.github/actions/issue_add_last_updated@add-last-updated-workflow | ||
``` | ||
|
||
|
||
In your test repo, create a test issue and your test repo's workflow | ||
```bash | ||
TEST_REPO='tenstorrent/tt-mlir' | ||
TEST_REPO_BRANCH='2165-point-last-updated-workflow-to-tt-github-actions' | ||
|
||
ISSUE_NUMBER=$(gh issue create -R $TEST_REPO --title 'Test issue last updated' --body 'Test issue last updated' | grep -oP '(?<=issues\/)\d+') | ||
|
||
gh workflow run issue-last-updated.yml -R $TEST_REPO --ref $TEST_REPO_BRANCH -f issue_number=$ISSUE_NUMBER | ||
``` | ||
|
||
After you confirmed the workflow passses (in this case `tt-mlir`) you can delete your test issue. | ||
|
||
```bash | ||
gh issue delete -R tenstorrent/tt-mlir $ISSUE_NUMBER | ||
``` | ||
|
||
Be sure to test show your test results in your PR! |
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,132 @@ | ||
# .github/actions/execute-action/action.yml | ||
|
||
name: Update Project date on issue update | ||
inputs: | ||
project_id: | ||
description: "Github Project ID" | ||
type: string | ||
required: true | ||
field_id: | ||
description: "Github Project Field ID" | ||
type: string | ||
required: true | ||
issue_number: | ||
description: "Github issue number used for testing" | ||
type: string | ||
required: true | ||
gh_token: | ||
description: "Github Token" | ||
type: string | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
|
||
- name: Get Issue ID | ||
id: get_issue_id | ||
shell: bash | ||
run: | | ||
issue_number="${{ inputs.issue_number }}" | ||
echo "Issue number: ${issue_number}" | ||
issue_details=$(curl -H "Authorization: Bearer ${{ inputs.gh_token }}" -s "https://api.github.com/repos/${{ github.repository }}/issues/$issue_number") | ||
issue_id=$(echo "$issue_details" | jq -r '.node_id') | ||
echo "Issue ID: ${issue_id}" | ||
echo "issue_id=$issue_id" >> $GITHUB_ENV | ||
- name: Get Item ID for Issue | ||
shell: bash | ||
id: get_item_id_by_issue_id | ||
run: | | ||
# Initialize variables | ||
CURSOR=null | ||
ITEM_ID="" | ||
# Define the GraphQL query as a string | ||
QUERY='query($projectId: ID!, $cursor: String) { | ||
node(id: $projectId) { | ||
... on ProjectV2 { | ||
items(first: 100, after: $cursor) { | ||
nodes { | ||
id | ||
content { | ||
... on Issue { | ||
id | ||
} | ||
} | ||
} | ||
pageInfo { | ||
hasNextPage | ||
endCursor | ||
} | ||
} | ||
} | ||
} | ||
}' | ||
while : ; do | ||
# Construct JSON payload using jq for proper formatting | ||
JSON_PAYLOAD=$(jq -n \ | ||
--arg query "$QUERY" \ | ||
--arg projectId "${{ inputs.project_id }}" \ | ||
--arg cursor "$CURSOR" \ | ||
'{ query: $query, variables: { projectId: $projectId, cursor: $cursor }}') | ||
# Make the GraphQL request | ||
RESPONSE=$(curl -s -X POST -H "Authorization: Bearer ${{ inputs.gh_token }}" \ | ||
-H "Content-Type: application/json" \ | ||
-d "$JSON_PAYLOAD" \ | ||
https://api.github.com/graphql) | ||
# Debug: print entire response | ||
echo "RESPONSE: $RESPONSE" | ||
# Check if the response contains `items` data | ||
ITEMS_DATA=$(echo "$RESPONSE" | jq -r '.data.node.items.nodes' 2>/dev/null) | ||
if [[ "$ITEMS_DATA" == "null" ]]; then | ||
echo "Error: Items data not found. Please check your PROJECT_ID and GITHUB_TOKEN permissions." | ||
exit 1 | ||
fi | ||
# Parse the item ID if it matches the issue_id | ||
ITEM_ID=$(echo "$RESPONSE" | jq -r --arg issue_id "$issue_id" \ | ||
'.data.node.items.nodes[] | select(.content.id==$issue_id) | .id') | ||
# If ITEM_ID is found, output it and stop the loop | ||
if [[ -n "$ITEM_ID" && "$ITEM_ID" != "null" ]]; then | ||
echo "Found ITEM_ID: $ITEM_ID" | ||
echo "ITEM_ID=$ITEM_ID" >> $GITHUB_ENV # Save ITEM_ID to environment for future steps | ||
break | ||
fi | ||
# Extract pagination information | ||
HAS_NEXT_PAGE=$(echo "$RESPONSE" | jq -r '.data.node.items.pageInfo.hasNextPage') | ||
CURSOR=$(echo "$RESPONSE" | jq -r '.data.node.items.pageInfo.endCursor') | ||
# If no more pages, exit loop | ||
if [[ "$HAS_NEXT_PAGE" != "true" ]]; then | ||
echo "Issue not found in project items." | ||
break | ||
fi | ||
done | ||
- name: Use Found ITEM_ID | ||
shell: bash | ||
if: env.ITEM_ID # Only runs if ITEM_ID was set | ||
run: echo "The ITEM_ID is ${{ env.ITEM_ID }}" | ||
|
||
|
||
- name: Update Project Field | ||
shell: bash | ||
run: | | ||
current_date=$(date +%Y-%m-%d) | ||
curl -H "Authorization: Bearer ${{ inputs.gh_token }}" \ | ||
-H "Content-Type: application/json" \ | ||
-d "{ \"query\": \"mutation { updateProjectV2ItemFieldValue(input: { projectId: \\\"${{ inputs.project_id }}\\\", itemId: \\\"${{ env.ITEM_ID }}\\\", fieldId: \\\"${{ inputs.field_id }}\\\", value: { date: \\\"$current_date\\\" } }) { clientMutationId } }\" }" \ | ||
-X POST \ | ||
"https://api.github.com/graphql" |
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