diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4151a18..de14e4f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,20 +24,21 @@ jobs: steps: - uses: actions/checkout@v2 - with: - php-version: '7.4' - tools: pecl + - name: Copy .env run: php -r "file_exists('.env') || copy('.env.example', '.env');" + - name: Install Dependencies run: composer install --no-interaction --no-scripts --no-progress --prefer-dist + - name: Directory Permissions run: mkdir -p storage bootstrap/cache && chmod -R 777 storage bootstrap/cache + - name: Execute tests (Unit and Feature tests) via PHPUnit run: vendor/bin/phpunit - - name: Set production values - if: contains(github.ref, 'production') || contains(github.ref, 'master') + - name: Set production environment + if: contains(github.ref, 'production') run: | echo "::set-env name=IMAGE_NAME::$IMAGE_NAME_PRODUCTION" @@ -50,38 +51,41 @@ jobs: - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master with: - service_account_email: ${{ env.GCP_EMAIL }} service_account_key: ${{ env.GCP_KEY }} # Configure docker to use the gcloud command-line tool as a credential helper - run: | # Set up docker to authenticate # via gcloud command-line tool. gcloud auth configure-docker + # Push the Docker image to Google Container Registry - name: Publish - run: docker push "$REPO_ROOT"/"$GCP_PROJECT"/"$IMAGE_NAME":"$GITHUB_RUN_NUMBER" + run: | + docker push "$REPO_ROOT"/"$GCP_PROJECT"/"$IMAGE_NAME":"$GITHUB_RUN_NUMBER" deploy: name: Deploy to GCP Cloud Run needs: build runs-on: ubuntu-latest + env: + APP_ENV: "staging" steps: - - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master - with: - service_account_email: ${{ env.GCP_EMAIL }} - service_account_key: ${{ env.GCP_KEY }} - - name: Set production values if: contains(github.ref, 'production') || contains(github.ref, 'master') run: | + echo "::set-env name=APP_ENV::production" echo "::set-env name=IMAGE_NAME::$IMAGE_NAME_PRODUCTION" + - uses: GoogleCloudPlatform/github-actions/setup-gcloud@master + with: + service_account_key: ${{ env.GCP_KEY }} + # Deploy image to Cloud Run - - name: Deploying to staging + - name: Deploying run: | - gcloud --project "$GCP_PROJECT" run deploy "$IMAGE_NAME" \ - --region "$GCP_REGION" \ + gcloud --project "$GCP_PROJECT" \ + run deploy "$IMAGE_NAME" --region "$GCP_REGION" \ --image "$REPO_ROOT"/"$GCP_PROJECT"/"$IMAGE_NAME":"$GITHUB_RUN_NUMBER" \ --platform "managed" --port=80 \ --allow-unauthenticated \ No newline at end of file