Improvement - Acciones de Github - Adaptar Github Actions #7
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 - Update instance on Push | |
on: | |
pull_request: | |
types: [synchronize] | |
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}} | |
jobs: | |
update_develop_instance: | |
name: Update develop instance | |
runs-on: ubuntu-latest | |
steps: | |
- 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: Extract branch name | |
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 | |
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: Update 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 "cd /web/${{ env.BRANCH_CLEAN }} && git stash && git pull && wget --delete-after --no-check-certificate https://develop.sinergiacrm.org/${{ env.BRANCH_CLEAN }}/SticRepair.php && rm -rf /web/${{ env.BRANCH_CLEAN }}/cache" && wget --delete-after --no-check-certificate https://develop.sinergiacrm.org/${{ env.BRANCH_CLEAN }}) || echo "Branch doesn't exist in develop" | |
- 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 }} |