Hotfix - General - Corrección del script que da de alta los schedulers en inglés #22
Workflow file for this run
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
name: Develop - Create Instance on Opened or Reopened PR | |
on: | |
pull_request: | |
types: [opened, reopened] | |
branches: # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestbranchestags | |
- '**' # matches every branch | |
workflow_dispatch: | |
env: | |
DEVELOP_HOST: ${{ secrets.DEVELOP_HOST}} | |
DEVELOP_SSH_USERNAME: ${{ secrets.DEVELOP_SSH_USERNAME}} | |
DEVELOP_DOMAIN_NAME: ${{ secrets.DEVELOP_DOMAIN_NAME}} | |
MAIN_HOST: ${{ secrets.MAIN_HOST}} | |
MAIN_SSH_USERNAME: ${{ secrets.MAIN_SSH_USERNAME}} | |
jobs: | |
create_instance: | |
name: Create Instance on Opened or Reopened PR | |
runs-on: ubuntu-latest | |
steps: | |
- name: Extract branch name | |
run: echo ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} && echo 'BRANCH='${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} >> $GITHUB_ENV | |
- name: Install SSH Key | |
uses: shimataro/ssh-key-action@v2 | |
with: | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
known_hosts: unnecessary | |
- name: Adding Known Hosts Develop | |
run: ssh-keyscan -H $DEVELOP_HOST >> ~/.ssh/known_hosts | |
- name: Adding Known Hosts Main | |
run: ssh-keyscan -H $MAIN_HOST >> ~/.ssh/known_hosts | |
- name: Get Available database name | |
run: | |
DATABASE_NAME=$(ssh $DEVELOP_SSH_USERNAME@$DEVELOP_HOST "mysql -h 127.0.0.1 -u '${{ secrets.DEVELOP_DB_USERNAME }}' --password='${{ secrets.DEVELOP_DB_PASSWORD }}' -N -e 'select schema_name | |
from information_schema.schemata | |
where | |
SCHEMA_NAME not in ( | |
SELECT | |
TABLE_SCHEMA | |
from information_schema.tables | |
where table_name like \"stic%\" | |
group by TABLE_SCHEMA | |
) | |
and SCHEMA_NAME like \"mydevelop%\" | |
order by SCHEMA_NAME LIMIT 1'") && | |
echo $DATABASE_NAME && | |
(echo "DATABASE_NAME=$DATABASE_NAME" >> $GITHUB_ENV) | |
- name: Extract branch clean | |
run: echo 'BRANCH_CLEAN='`echo ${{ env.BRANCH }} | sed -e 's/[^a-zA-Z0-9_/]//g'` >> $GITHUB_ENV | |
- name: Set current date as env variable | |
run: echo 'NOW='$(date +'%Y-%m-%d %H:%M:%S') >> $GITHUB_ENV | |
- name: echo environment variables | |
run: echo ${{ env }} | |
# - name: Delete develop instance | |
# run: ssh $DEVELOP_SSH_USERNAME@$DEVELOP_HOST "test -e /web/${{ env.BRANCH_CLEAN }}" && (echo "Directory branch exists" && ssh $DEVELOP_SSH_USERNAME@$DEVELOP_HOST "rm -rf /web/${{ env.BRANCH_CLEAN }} && mysql -h 127.0.0.1 -u $DEVELOP_DB_USERNAME --password=$DEVELOP_DB_PASSWORD -e 'drop database if exists ${{ env.DATABASE_NAME }}; create database ${{ env.DATABASE_NAME }};'") || echo "Branch doesn't exist in develop" | |
- name: Create Instance in develop through Main | |
run: ssh $MAIN_SSH_USERNAME@$MAIN_HOST "cd scripts/create && bash create.sh -b ${{ env.BRANCH }} -i $DEVELOP_DOMAIN_NAME -p /web/${{ env.BRANCH_CLEAN }} -db ${{ env.DATABASE_NAME }} -d -y" | |
- name: Set Clean git branch | |
run: ssh $DEVELOP_SSH_USERNAME@$DEVELOP_HOST "test -e /web/${{ env.BRANCH_CLEAN }}" && (echo "Directory branch exists" && ssh $DEVELOP_SSH_USERNAME@$DEVELOP_HOST "cd /web/${{ env.BRANCH_CLEAN }} && git stash && git reset && git pull") | |
- name: Get project data | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
ORGANIZATION: SinergiaTIC | |
PROJECT_NUMBER: 2 | |
PR_ID: ${{ github.event.pull_request.node_id }} | |
run: | | |
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 | |
} | |
} | |
} | |
} | |
items(first:100) { | |
nodes { | |
... on ProjectV2Item { | |
id | |
} | |
} | |
} | |
} | |
} | |
}' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json | |
echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV | |
echo 'URL_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "URLValidationInstance") | .id' project_data.json) >> $GITHUB_ENV | |
echo 'DB_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "DBValidationInstance") | .id' project_data.json) >> $GITHUB_ENV | |
echo 'DATE_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "DateValidationInstance") | .id' project_data.json) >> $GITHUB_ENV | |
echo 'CURRENT_DATE='$(date +'%Y-%m-%d') >> $GITHUB_ENV | |
- name: Get PR Item ID | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
PR_ID: ${{ github.event.pull_request.node_id }} | |
run: | | |
item_id="$( gh api graphql -f query=' | |
mutation($project:ID!, $pr:ID!) { | |
addProjectV2ItemById(input: {projectId: $project, contentId: $pr}) { | |
item { | |
id | |
} | |
} | |
}' -f project=$PROJECT_ID -f pr=$PR_ID --jq '.data.addProjectV2ItemById.item.id')" | |
echo 'ITEM_ID='$item_id >> $GITHUB_ENV | |
- name: Change Fields | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
run: | | |
gh api graphql -f query=' | |
mutation ( | |
$project: ID! | |
$item: ID! | |
$url_field: ID! | |
$url_value: String! | |
) { | |
set_status: updateProjectV2ItemFieldValue(input: { | |
projectId: $project | |
itemId: $item | |
fieldId: $url_field | |
value: { | |
text: $url_value | |
} | |
}) { | |
projectV2Item { | |
id | |
} | |
} | |
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f url_field=$URL_FIELD_ID -f url_value=https://${{ env.DEVELOP_DOMAIN_NAME}}/${{ env.BRANCH_CLEAN }} --silent | |
gh api graphql -f query=' | |
mutation ( | |
$project: ID! | |
$item: ID! | |
$db_field: ID! | |
$db_value: String! | |
) { | |
set_status: updateProjectV2ItemFieldValue(input: { | |
projectId: $project | |
itemId: $item | |
fieldId: $db_field | |
value: { | |
text: $db_value | |
} | |
}) { | |
projectV2Item { | |
id | |
} | |
} | |
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f db_field=$DB_FIELD_ID -f db_value=${{ env.DATABASE_NAME }} --silent | |
gh api graphql -f query=' | |
mutation ( | |
$project: ID! | |
$item: ID! | |
$date_field: ID! | |
$date_value: Date! | |
) { | |
set_status: updateProjectV2ItemFieldValue(input: { | |
projectId: $project | |
itemId: $item | |
fieldId: $date_field | |
value: { | |
date: $date_value | |
} | |
}) { | |
projectV2Item { | |
id | |
} | |
} | |
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f date_field=$DATE_FIELD_ID -f date_value=$CURRENT_DATE --silent | |
- name: Create or Edit PR comment | |
uses: thollander/actions-comment-pull-request@v1 | |
with: | |
message: | | |
Actions executed at: ${{ env.NOW }}. | |
comment_includes: 'Actions executed at:' | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |