Skip to content

👌🏻IMPROVE: make action callable via workflow call #42

👌🏻IMPROVE: make action callable via workflow call

👌🏻IMPROVE: make action callable via workflow call #42

name: Update Deployment Issue
on:
workflow_dispatch:
inputs:
organization:
required: false
default: "CoveredCA"
description: Name of the organization the project is in
project-number:
required: false
default: 5
description: The number of the project from the project web url
application-name:
required: true
default: "cca-salesforce-sapi"
description: The name of the application the deployment issue was created for
environment:
required: true
default: "dev"
description: The enmviropnment the deployment issue is calling for
version:
required: true
default: "1.0.10"
description: The version of the application to be deployed to the environment
debug:
required: false
default: false
description: more verbose output for debugging purposes
workflow_call:
inputs:
organization:
required: false
default: "CoveredCA"
description: Name of the organization the project is in
project-number:
required: false
default: 5
description: The number of the project from the project web url
application-name:
required: true
default: "cca-salesforce-sapi"
description: The name of the application the deployment issue was created for
environment:
required: true
default: "dev"
description: The enmviropnment the deployment issue is calling for
version:
required: true
default: "1.0.10"
description: The version of the application to be deployed to the environment
jobs:
updateIssue:
name: Update Project Issue
runs-on: ubuntu-latest
steps:
- name: Get token from Github App
id: app-token
uses: CoveredCA/common-devops/packages/app-token@main
with:
client-id: ${{ secrets.MULESOFT_GITHUBAPP_CLIENTID }}
privatekey: ${{ secrets.MULESOFT_GITHUBAPP_PRIVATEKEY }}
- name: Get project ID
id: project-id
shell: bash
env:
GITHUB_TOKEN: ${{ env.github_automationbot_token }}
GH_TOKEN: ${{ env.github_automationbot_token }}
run: |
echo "******************"
echo "* Get Project ID *"
echo "******************"
PROJECT_ID=$(gh api graphql -f query='{
organization(login: "${{ inputs.organization }}") {
login
projectsV2(first: 100) {
edges {
node {
id
title
}
}
}
}
}' | jq -r '.data.organization.projectsV2.edges[] | select(.node.title | test("Deployment")) | .node.id')
echo "PROJECT_ID=$PROJECT_ID" >> $GITHUB_OUTPUT
- name: DEBUG - PROJECT_ID
if: ${{ github.event.inputs.debug == 'true' }}
run: echo "PROJECT_ID = ${{steps.project-id.outputs.PROJECT_ID}}"
- name: Get issue ID
id: issue-id
shell: bash
env:
GITHUB_TOKEN: ${{ env.github_automationbot_token }}
GH_TOKEN: ${{ env.github_automationbot_token }}
run: |
echo "****************"
echo "* Get Issue ID *"
echo "****************"
# Initial cursor is empty
CURSOR=""
# Loop until all pages are fetched
while : ; do
# Execute GraphQL query
RESPONSE=$(gh api graphql -f query='
query($org: String!, $number: Int!, $cursor: String) {
organization(login: $org) {
projectV2(number: $number) {
items(first: 100, after: $cursor) {
pageInfo {
hasNextPage
endCursor
}
nodes {
id
content {
... on Issue {
id
number
title
}
}
}
}
}
}
}' -f org="${{ inputs.organization }}" -F number="${{ inputs.project-number }}" -f cursor="$CURSOR")
# Parse items and do something with them, e.g., append to a file
echo "$RESPONSE" | jq '.data.organization.projectV2.items.nodes[]' >> deployment_issues.json
# Check if there's a next page; if not, break the loop
HAS_NEXT_PAGE=$(echo "$RESPONSE" | jq '.data.organization.projectV2.items.pageInfo.hasNextPage')
if [ "$HAS_NEXT_PAGE" != "true" ]; then
break
fi
# Update cursor to fetch next page
CURSOR=$(echo "$RESPONSE" | jq -r '.data.organization.projectV2.items.pageInfo.endCursor')
done
echo "All items fetched successfully."
echo "Parsing output data file"
ISSUE_ID=$(jq -r '. | select(.content.title | test("Deployment")) | select(.content.title | test("${{ inputs.environment }}")) | select(.content.title | test("${{ inputs.application-name }}")) | select(.content.title | test("${{ inputs.version }}")) | .id' deployment_issues.json)
echo "ISSUE_ID=$ISSUE_ID" >> $GITHUB_OUTPUT
- name: DEBUG - ISSUE_ID
if: ${{ github.event.inputs.debug == 'true' }}
run: echo "ISSUE_ID = ${{steps.issue-id.outputs.ISSUE_ID}}"
- name: Get field ID
id: field-id
shell: bash
env:
GITHUB_TOKEN: ${{ env.github_automationbot_token }}
GH_TOKEN: ${{ env.github_automationbot_token }}
run: |
echo "******************"
echo "* Get Field ID's *"
echo "******************"
FIELD_DATA=$(gh api graphql -f query='
query($org: String!, $number: Int!) {
organization(login: $org){
projectV2(number: $number) {
id
fields(first:20) {
nodes {
... on ProjectV2Field {
id
name
}
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
}
}
}' -f org="${{ inputs.organization }}" -F number="${{ inputs.project-number }}" | jq '.data.organization.projectV2.fields.nodes[] | select((.name | test("Environment")) or (.name | test("Version")))')
FIELD_ID_ENVIRONMENT=$(echo "$FIELD_DATA" | jq -r '. | select(.name | test("Environment")) | .id')
FIELD_ID_VERSION=$(echo "$FIELD_DATA" | jq -r '. | select(.name | test("Version")) | .id')
echo "FIELD_ID_ENVIRONMENT=$FIELD_ID_ENVIRONMENT" >> $GITHUB_OUTPUT
echo "FIELD_ID_VERSION=$FIELD_ID_VERSION" >> $GITHUB_OUTPUT
- name: DEBUG - FIELD_ID
if: ${{ github.event.inputs.debug == 'true' }}
run: |
echo "FIELD_ID_ENVIRONMENT = ${{steps.field-id.outputs.FIELD_ID_ENVIRONMENT}}"
echo "FIELD_ID_VERSION = ${{steps.field-id.outputs.FIELD_ID_VERSION}}"
- name: Get Environment Field Option ID
id: environment-option-id
shell: bash
env:
GITHUB_TOKEN: ${{ env.github_automationbot_token }}
GH_TOKEN: ${{ env.github_automationbot_token }}
run: |
echo "***********************************"
echo "* Get Environment Field Option ID *"
echo "***********************************"
FIELD_ENVIRONMENT_OPTION_ID=$(gh api graphql -f query='
query($org: String!, $number: Int!) {
organization(login: $org){
projectV2(number: $number) {
id
fields(first:20) {
nodes {
... on ProjectV2Field {
id
name
}
... on ProjectV2SingleSelectField {
id
name
options {
id
name
}
}
}
}
}
}
}' -f org="${{ inputs.organization }}" -F number="${{ inputs.project-number }}" | jq '.data.organization.projectV2.fields.nodes[] | select(.name | test("Environment")) | .options[]' | jq -r '. | select(.name | test("${{ inputs.environment }}")) | .id')
echo "FIELD_ENVIRONMENT_OPTION_ID=$FIELD_ENVIRONMENT_OPTION_ID" >> $GITHUB_OUTPUT
- name: DEBUG - FIELD_ENVIRONMENT_OPTION_ID
if: ${{ github.event.inputs.debug == 'true' }}
run: echo "FIELD_ENVIRONMENT_OPTION_ID = ${{steps.environment-option-id.outputs.FIELD_ENVIRONMENT_OPTION_ID}}"
- name: Update Deployment Issue Environment Field
shell: bash
env:
GITHUB_TOKEN: ${{ env.github_automationbot_token }}
GH_TOKEN: ${{ env.github_automationbot_token }}
run: |
echo ""
echo "Updating Environment Field"
echo ""
echo "Graph Query 1"
echo ""
echo "gh api graphql -f query='
mutation {
updateProjectV2ItemFieldValue(
input: {
projectId: \"${{ steps.project-id.outputs.PROJECT_ID }}\"
itemId: \"${{ steps.issue-id.outputs.ISSUE_ID }}\"
fieldId: \"${{ steps.field-id.outputs.FIELD_ID_ENVIRONMENT }}\"
value: {
singleSelectOptionId: \"${{ steps.environment-option-id.outputs.FIELD_ENVIRONMENT_OPTION_ID }}\"
}
}
)
{
projectV2Item {
id
}
}
}'"
echo ""
echo "Running Query 1 now..."
echo ""
gh api graphql -f query='
mutation {
updateProjectV2ItemFieldValue(
input: {
projectId: "${{steps.project-id.outputs.PROJECT_ID}}"
itemId: "${{ steps.issue-id.outputs.ISSUE_ID }}"
fieldId: "${{ steps.field-id.outputs.FIELD_ID_ENVIRONMENT }}"
value: {
singleSelectOptionId: "${{ steps.environment-option-id.outputs.FIELD_ENVIRONMENT_OPTION_ID }}"
}
}
)
{
projectV2Item {
id
}
}
}'
- name: Update Deployment Issue Version Field
shell: bash
env:
GITHUB_TOKEN: ${{ env.github_automationbot_token }}
GH_TOKEN: ${{ env.github_automationbot_token }}
run: |
echo ""
echo "Updating Version Field"
echo ""
echo "Graph Query 2"
echo ""
echo "gh api graphql -f query='
mutation {
updateProjectV2ItemFieldValue(
input: {
projectId: \"${{steps.project-id.outputs.PROJECT_ID}}\"
itemId: \"${{ steps.issue-id.outputs.ISSUE_ID }}\"
fieldId: \"${{ steps.field-id.outputs.FIELD_ID_VERSION }}\"
value: {
text: \"${{ inputs.version }}\"
}
}
)
{
projectV2Item {
id
}
}
}'"
echo ""
echo "Running query 2 now..."
echo ""
gh api graphql -f query='
mutation {
updateProjectV2ItemFieldValue(
input: {
projectId: "${{steps.project-id.outputs.PROJECT_ID}}"
itemId: "${{ steps.issue-id.outputs.ISSUE_ID }}"
fieldId: "${{ steps.field-id.outputs.FIELD_ID_VERSION }}"
value: {
text: "${{ inputs.version }}"
}
}
)
{
projectV2Item {
id
}
}
}'