Skip to content

ci: further improve pr deployments #8764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr-cleanup.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Cleanup PR
name: Cleanup PR deployment and image
on:
pull_request:
types: [closed]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This action will trigger when a PR is commentted containing /review-pr by a member of the org.
# This action will trigger when a PR is commented on with `/deploy-pr` or when the workflow is manually triggered.
name: Deploy PR
on:
issue_comment:
Expand Down
67 changes: 51 additions & 16 deletions scripts/deploy-pr.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,67 @@
#!/usr/bin/env bash
# Usage: ./deploy-pr.sh --skip-build
# Usage: ./deploy-pr.sh [--skip-build -s] [--dry-run -n] [--yes -y]
# deploys the current branch to a PR environment and posts login credentials to
# [#pr-deployments](https://codercom.slack.com/archives/C05DNE982E8) Slack channel
# if --skip-build is passed, the build step will be skipped and the last build image will be used

set -euox pipefail
set -euo pipefail

branchName=$(gh pr view --json headRefName | jq -r .headRefName)
# default settings
skipBuild=false
dryRun=false
confirm=true

# parse arguments
for arg in "$@"; do
case $arg in
-s | --skip-build)
skipBuild=true
shift # Remove --skip-build from processing
;;
-n | --dry-run)
dryRun=true
shift # Remove --dry-run from processing
;;
-y | --yes)
confirm=false
shift # Remove --yes from processing
;;
*)
shift # Remove generic argument from processing
;;
esac
done

if [[ "$branchName" == "main" ]]; then
prNumber=$(git rev-parse --short HEAD)
else
prNumber=$(gh pr view --json number | jq -r .number)
# confirm if not passed -y or --yes
if $confirm; then
read -p "Are you sure you want to deploy? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi

# if --skip-build is passed, the build job will be skipped and the last built image will be used
if [[ "$*" == *--skip-build* ]]; then
skipBuild=true
# get branch name and pr number
branchName=$(gh pr view --json headRefName | jq -r .headRefName)
prNumber=$(gh pr view --json number | jq -r .number)

if $skipBuild; then
#check if the image exists
foundTag=$(curl -fsSL https://github.com/coder/coder/pkgs/container/coder-preview | grep -o "$prNumber" | head -n 1)
if [ -z "${foundTag}" ]; then
foundTag=$(curl -fsSL https://github.com/coder/coder/pkgs/container/coder-preview | grep -o "$prNumber" | head -n 1) || true
echo "foundTag is: '${foundTag}'"
if [[ -z "${foundTag}" ]]; then
echo "Image not found"
echo "${prNumber} tag not found in ghcr.io/coder/coder-preview"
echo "Please remove --skip-build and try again"
exit 1
fi
else
skipBuild=false
fi

gh workflow run pr-deploy.yaml --ref "${branchName}" -f pr_number="${prNumber}" -f skip_build="${skipBuild}"
if $dryRun; then
echo "dry run"
echo "branchName: ${branchName}"
echo "prNumber: ${prNumber}"
echo "skipBuild: ${skipBuild}"
exit 0
fi

gh workflow run pr-deploy.yaml --ref "${branchName}" -f "pr_number=${prNumber}" -f "skip_build=${skipBuild}"
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy