Skip to content

Commit 41b36d1

Browse files
committed
add skipping build
1 parent 3ad658d commit 41b36d1

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

.github/workflows/pr-deploy.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
pr_number:
99
description: "PR number"
1010
required: true
11+
skip_build:
12+
description: "Skip build job"
13+
required: false
14+
default: false
1115

1216
env:
1317
REPO: ghcr.io/coder/coder-preview
@@ -73,6 +77,9 @@ jobs:
7377

7478
build:
7579
needs: pr_commented
80+
# Skips the build job if the workflow was triggered by a workflow_dispatch event and the skip_build input is set to true
81+
# or if the workflow was triggered by an issue_comment event and the comment body contains --skip-build
82+
if: (github.event_name == 'workflow_dispatch' && github.event.inputs.skip_build == 'false') || (github.event_name == 'issue_comment' && contains(github.event.comment.body, '--skip-build') != true)
7683
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
7784
env:
7885
DOCKER_CLI_EXPERIMENTAL: "enabled"
@@ -120,7 +127,8 @@ jobs:
120127
121128
deploy:
122129
needs: [build, pr_commented]
123-
if: needs.build.result == 'success'
130+
# Run deploy job only if build job was successful or skipped but not if it failed
131+
if: needs.build.result != 'failure' && needs.build.result != 'cancelled'
124132
runs-on: "ubuntu-latest"
125133
env:
126134
CODER_IMAGE_TAG: ${{ needs.pr_commented.outputs.CODER_IMAGE_TAG }}

scripts/deploy-pr.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
#!/usr/bin/env bash
2-
# Usage: ./deploy-pr.sh
3-
# deploys the current branch to a PR environment and posts login credentials to [#pr-deployments](https://codercom.slack.com/archives/C05DNE982E8) Slack channel
2+
# Usage: ./deploy-pr.sh --skip-build
3+
# deploys the current branch to a PR environment and posts login credentials to
4+
# [#pr-deployments](https://codercom.slack.com/archives/C05DNE982E8) Slack channel
5+
# if --skip-build is passed, the build step will be skipped and the last build image will be used
6+
47
set -euox pipefail
58

9+
# if --skip-build is passed, the build step will be skipped and the last build image will be used
10+
if [[ "$*" == *--skip-build* ]]; then
11+
skipBuild=true
12+
fi
13+
614
branchName=$(gh pr view --json headRefName | jq -r .headRefName)
715

816
if [[ "$branchName" == "main" ]]; then
9-
gh workflow run pr-deploy.yaml --ref $branchName -f pr_number=$(git rev-parse --short HEAD)
17+
gh workflow run pr-deploy.yaml --ref $branchName -f pr_number=$(git rev-parse --short HEAD) -f skip_build=$skipBuild
1018
else
11-
gh workflow run pr-deploy.yaml --ref $branchName -f pr_number=$(gh pr view --json number | jq -r .number)
19+
gh workflow run pr-deploy.yaml --ref $branchName -f pr_number=$(gh pr view --json number | jq -r .number) -f skip_build=$skipBuild
1220
fi

0 commit comments

Comments
 (0)