From eadbc4358e0e16bd9fcefdbb14988c69fc6a1263 Mon Sep 17 00:00:00 2001 From: TechMaveGit <34518191+basantsd@users.noreply.github.com> Date: Tue, 9 Jul 2024 11:25:26 +0530 Subject: [PATCH] action updated --- action.yml | 59 +++++++++++++++++++++++++++++++++++++++++++++++++-- entrypoint.sh | 55 ----------------------------------------------- 2 files changed, 57 insertions(+), 57 deletions(-) delete mode 100644 entrypoint.sh diff --git a/action.yml b/action.yml index 120f15e..fb37711 100644 --- a/action.yml +++ b/action.yml @@ -38,7 +38,62 @@ inputs: runs: using: 'composite' steps: - - run: ./entrypoint.sh + - run: | + set -e + + create_github_issue() { + local message=$1 + curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/$REPO/issues \ + -d "{\"title\":\"CI/CD Action Failed\",\"body\":\"$message\"}" + } + + job=${{ inputs.job }} + + trap 'create_github_issue "Job: $job failed.\n\nCheck the logs for details."' ERR + + if [ "$job" == "ci" ]; then + # CI steps + echo "Running CI steps..." + composer install --prefer-dist --no-progress --no-suggest --no-interaction + php artisan test + + elif [ "$job" == "cd" ]; then + # CD steps + echo "Running CD steps..." + composer install --prefer-dist --no-progress --no-suggest --no-interaction + ssh -o StrictHostKeyChecking=no -i $VPS_PRIVATE_KEY $VPS_USERNAME@$VPS_HOST << EOF + cd $DEPLOY_PATH + sudo chown -R $USER:www-data storage/ bootstrap/cache public/ + sudo chmod -R 775 storage bootstrap/cache public/ + git reset --hard + git clean -fd + git pull origin $PRODUCTION_BRANCH + /usr/bin/php$PHP_VERSION $(which composer) install --no-dev --prefer-dist --optimize-autoloader + /usr/bin/php$PHP_VERSION artisan optimize + /usr/bin/php$PHP_VERSION artisan optimize:clear + /usr/bin/php$PHP_VERSION artisan storage:link + EOF + + elif [ "$job" == "code_cleanup" ]; then + # Code Cleanup steps + echo "Running code cleanup steps..." + composer install --prefer-dist --no-progress --no-suggest --no-interaction + composer require --dev laravel/pint + composer require --dev squizlabs/php_codesniffer + npm install + ./vendor/bin/pint || vendor/bin/pint + ./vendor/bin/phpcs --standard=PSR12 app/ routes/ tests/ resources/ || vendor/bin/phpcs --standard=PSR12 app/ routes/ tests/ resources/ + npx eslint resources/**/*.js + git config --local user.name "github-actions[bot]" + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git add -A + git commit -m "Apply code style fixes" || echo "No changes to commit" + else + echo "Invalid job" + exit 1 + fi shell: bash env: JOB: ${{ inputs.job }} @@ -51,5 +106,5 @@ runs: GITHUB_TOKEN: ${{ inputs.github_token }} REPO: ${{ inputs.repo }} branding: - icon: 'wind' + icon: 'terminal' color: 'blue' diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index 270e6ff..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash -set -e - -create_github_issue() { - local message=$1 - curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" \ - -H "Accept: application/vnd.github.v3+json" \ - https://api.github.com/repos/$REPO/issues \ - -d "{\"title\":\"CI/CD Action Failed\",\"body\":\"$message\"}" -} - -job=$JOB - -trap 'create_github_issue "Job: $job failed.\n\nCheck the logs for details."' ERR - -if [ "$job" == "ci" ]; then - # CI steps - echo "Running CI steps..." - composer install --prefer-dist --no-progress --no-suggest --no-interaction - php artisan test - -elif [ "$job" == "cd" ]; then - # CD steps - echo "Running CD steps..." - composer install --prefer-dist --no-progress --no-suggest --no-interaction - ssh -o StrictHostKeyChecking=no -i $VPS_PRIVATE_KEY $VPS_USERNAME@$VPS_HOST - cd $DEPLOY_PATH - sudo chown -R $USER:www-data storage/ bootstrap/cache public/ - sudo chmod -R 775 storage bootstrap/cache public/ - git reset --hard - git clean -fd - git pull origin $PRODUCTION_BRANCH - /usr/bin/php$PHP_VERSION $(which composer) install --no-dev --prefer-dist --optimize-autoloader - /usr/bin/php$PHP_VERSION artisan optimize - /usr/bin/php$PHP_VERSION artisan optimize:clear - /usr/bin/php$PHP_VERSION artisan storage:link - -elif [ "$job" == "code_cleanup" ]; then - # Code Cleanup steps - echo "Running code cleanup steps..." - composer install --prefer-dist --no-progress --no-suggest --no-interaction - composer require --dev laravel/pint - composer require --dev squizlabs/php_codesniffer - npm install - ./vendor/bin/pint || vendor/bin/pint - ./vendor/bin/phpcs --standard=PSR12 app/ routes/ tests/ resources/ || vendor/bin/phpcs --standard=PSR12 app/ routes/ tests/ resources/ - npx eslint resources/**/*.js - git config --local user.name "github-actions[bot]" - git config --local user.email "github-actions[bot]@users.noreply.github.com" - git add -A - git commit -m "Apply code style fixes" || echo "No changes to commit" -else - echo "Invalid job" - exit 1 -fi