diff --git a/.github/workflows/Develop_CreateInstanceOnOpenedPR.yml b/.github/workflows/Develop_CreateInstanceOnOpenedPR.yml index c6b0e05faa8..d155350c6ec 100644 --- a/.github/workflows/Develop_CreateInstanceOnOpenedPR.yml +++ b/.github/workflows/Develop_CreateInstanceOnOpenedPR.yml @@ -16,6 +16,8 @@ jobs: 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: @@ -41,8 +43,6 @@ jobs: order by SCHEMA_NAME LIMIT 1'") && echo $DATABASE_NAME && (echo "DATABASE_NAME=$DATABASE_NAME" >> $GITHUB_ENV) - - name: Extract branch name - run: echo 'BRANCH='${{ github.head_ref }} >> $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 diff --git a/.github/workflows/Develop_DeleteInstanceOnClosedPR.yml b/.github/workflows/Develop_DeleteInstanceOnClosedPR.yml index 3055309a301..1a1d42b4bb3 100644 --- a/.github/workflows/Develop_DeleteInstanceOnClosedPR.yml +++ b/.github/workflows/Develop_DeleteInstanceOnClosedPR.yml @@ -23,7 +23,7 @@ jobs: - name: Adding Known Hosts Develop run: ssh-keyscan -H $DEVELOP_HOST >> ~/.ssh/known_hosts - name: Extract branch name - run: echo 'BRANCH='${{ github.head_ref }} >> $GITHUB_ENV + run: echo ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} && echo 'BRANCH='${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} >> $GITHUB_ENV - name: Extract branch clean run: echo 'BRANCH_CLEAN='`echo ${{ env.BRANCH }} | sed -e 's/[^a-zA-Z0-9_/]//g'` >> $GITHUB_ENV - name: Get Develop instance database name diff --git a/.github/workflows/Develop_ReinstallInstanceOnUserAction.yml b/.github/workflows/Develop_ReinstallInstanceOnUserAction.yml new file mode 100644 index 00000000000..eaa0f984303 --- /dev/null +++ b/.github/workflows/Develop_ReinstallInstanceOnUserAction.yml @@ -0,0 +1,167 @@ +name: Develop - Reinstall Instance on User Action +on: + 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: + reinstall_instance: + name: Reinstall Instance on User Action + 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: Extract branch clean + run: echo 'BRANCH_CLEAN='`echo ${{ env.BRANCH }} | sed -e 's/[^a-zA-Z0-9_/]//g'` >> $GITHUB_ENV + - name: Get Develop instance database name + run: echo 'DATABASE_NAME='`ssh $DEVELOP_SSH_USERNAME@$DEVELOP_HOST grep "db_name" /web/${{ env.BRANCH_CLEAN }}/config_override.php | sed "s/.*=.'//g" | sed "s/';.*//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 }} diff --git a/.github/workflows/Develop_UpdateInstanceOnPush.yml b/.github/workflows/Develop_UpdateInstanceOnPush.yml index 9c23e02ec1e..63f40d574dd 100644 --- a/.github/workflows/Develop_UpdateInstanceOnPush.yml +++ b/.github/workflows/Develop_UpdateInstanceOnPush.yml @@ -21,7 +21,7 @@ jobs: - name: Adding Known Hosts Develop run: ssh-keyscan -H $DEVELOP_HOST >> ~/.ssh/known_hosts - name: Extract branch name - run: echo 'BRANCH='${{ github.head_ref }} >> $GITHUB_ENV + run: echo ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} && echo 'BRANCH='${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} >> $GITHUB_ENV - name: Extract branch clean run: echo 'BRANCH_CLEAN='`echo ${{ env.BRANCH }} | sed -e 's/[^a-zA-Z0-9_/]//g'` >> $GITHUB_ENV - name: Get Develop instance database name diff --git a/.github/workflows/Projects_AddPRToProjectUpdates.yml b/.github/workflows/Projects_AddPRToProjectUpdates.yml deleted file mode 100644 index 87a32a25fd6..00000000000 --- a/.github/workflows/Projects_AddPRToProjectUpdates.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: Add PR to project updates -on: - pull_request: - types: - - opened - - reopened - branches: - - 'master' -jobs: - track_pr: - runs-on: ubuntu-latest - steps: - - name: Get project data - env: - GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} - ORGANIZATION: SinergiaTIC - PROJECT_NUMBER: 2 - 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 - } - } - } - } - } - } - }' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json - echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV - - name: Add PR to project updates - 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 diff --git a/.github/workflows/Projects_ChangeStatusReadyForNextRelease.yml b/.github/workflows/Projects_ChangeStatusReadyForNextRelease.yml index ae65b9444a0..366e675d445 100644 --- a/.github/workflows/Projects_ChangeStatusReadyForNextRelease.yml +++ b/.github/workflows/Projects_ChangeStatusReadyForNextRelease.yml @@ -1,4 +1,4 @@ -name: Projects Change Status Ready for Next Release +name: Projects - Change Status Ready for Next Release on: pull_request_target: types: diff --git a/.github/workflows/Projects_MoveToRelease.yml b/.github/workflows/Projects_MoveToRelease.yml index 34bd4fcfd08..3e92fc15af4 100644 --- a/.github/workflows/Projects_MoveToRelease.yml +++ b/.github/workflows/Projects_MoveToRelease.yml @@ -1,5 +1,5 @@ -name: Projects Move to release +name: Projects - Move to release on: release: types: [published]