From a43b96f191db31cd2ae8b92b6cff380a985b9de7 Mon Sep 17 00:00:00 2001 From: Fery Wardiyanto Date: Thu, 29 Feb 2024 07:44:52 +0700 Subject: [PATCH] chore(ci): fix deployment target url Signed-off-by: Fery Wardiyanto --- .github/workflows/deploy.yml | 2 +- .github/workflows/prepare.yml | 15 ++++++++------- scripts/deploy.php | 9 +++++++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4eb838b..1d487da 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -80,4 +80,4 @@ jobs: private-key: ${{ secrets.DEPLOY_SSH_RSAKEY }} ssh-config: ${{ secrets.DEPLOY_SSH_CONFIG }} verbosity: '' - dep: deploy -f scripts/deploy.php env=${{ env.APP_ENV }} --branch ${{ github.ref_name }} + dep: deploy -f scripts/deploy.php env=${{ env.APP_ENV }} --branch ${{ needs.prepare.outputs.target-branch }} diff --git a/.github/workflows/prepare.yml b/.github/workflows/prepare.yml index e76ed97..1e12108 100644 --- a/.github/workflows/prepare.yml +++ b/.github/workflows/prepare.yml @@ -11,12 +11,14 @@ on: outputs: composer-cache: value: ${{ jobs.build.outputs.composer-cache }} + should-reports: + value: ${{ jobs.build.outputs.should-reports }} + target-branch: + value: ${{ jobs.build.outputs.target-branch }} target-env: value: ${{ jobs.build.outputs.target-env }} target-url: value: ${{ jobs.build.outputs.target-url }} - should-reports: - value: ${{ jobs.build.outputs.should-reports }} jobs: labels: @@ -41,13 +43,11 @@ jobs: runs-on: ubuntu-latest name: Build for `${{ inputs.target }}` outputs: - target-env: ${{ env.APP_ENV }} - target-url: ${{ env.APP_URL }} composer-cache: ${{ steps.environments.outputs.composer-cache }} should-reports: ${{ steps.environments.outputs.should-reports }} - - # environment: - # name: ${{ inputs.target }} + target-branch: ${{ steps.environments.outputs.target-branch }} + target-env: ${{ env.APP_ENV }} + target-url: ${{ env.APP_URL }} env: APP_ENV: ${{ inputs.target }} @@ -85,6 +85,7 @@ jobs: CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} run: | git config user.name "Creasi.HQ" && git config user.email "developers@creasi.co" + echo "target-branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT echo "composer-cache=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT echo "should-reports=$([[ -n \"$CC_TEST_REPORTER_ID\" ]] && echo '1')" >> $GITHUB_OUTPUT diff --git a/scripts/deploy.php b/scripts/deploy.php index cbec1c4..7e82155 100644 --- a/scripts/deploy.php +++ b/scripts/deploy.php @@ -32,10 +32,15 @@ set('original_deploy_path', null); $env = get('labels')['env'] ?? null; + $host = currentHost(); $masterData = "storage/app/master-data.{$env}.xlsx"; $deployPath = get('deploy_path'); $appUrl = Env::get('APP_URL'); + if (\str_contains($appUrl, 'localhost')) { + $appUrl = 'https://'.$host->getAlias(); + } + if ($ghRef = Env::get('GITHUB_REF')) { [$_, $ref, $name] = explode('/', $ghRef); if ($ref === 'pull' && \is_numeric($name)) { @@ -48,9 +53,9 @@ if ($pullRequest !== null) { set('pull_request', $pullRequest); set('original_deploy_path', $deployPath); - set('deploy_path', $deployPath.'-'.$pullRequest); + $host->setDeployPath($deployPath.'-'.$pullRequest); - if (\getenv('GITHUB_ENV')) { + if (Env::get('GITHUB_ENV')) { $subdomain = \basename($deployPath); $appUrl = \str_replace($subdomain, $subdomain.'-'.$pullRequest, $appUrl);