Skip to content

Commit

Permalink
chore(ci): fix deployment target url
Browse files Browse the repository at this point in the history
Signed-off-by: Fery Wardiyanto <[email protected]>
  • Loading branch information
feryardiant committed Feb 29, 2024
1 parent f3c380d commit a43b96f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
15 changes: 8 additions & 7 deletions .github/workflows/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
Expand Down Expand Up @@ -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 "[email protected]"
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
Expand Down
9 changes: 7 additions & 2 deletions scripts/deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);

Expand Down

0 comments on commit a43b96f

Please sign in to comment.