Skip to content

Commit 17d7ab5

Browse files
authored
Merge pull request #923 from rahuldkjain/rahuldkjain/full-revamp
chore: add support of preview URLs in GitHub UI
2 parents 8468ec9 + ee75554 commit 17d7ab5

File tree

1 file changed

+51
-12
lines changed

1 file changed

+51
-12
lines changed

.github/workflows/deploy.yml

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,17 @@ jobs:
9393
# Deploy preview for dev branches (not master, only on direct push)
9494
if: github.ref != 'refs/heads/master' && github.event_name == 'push'
9595

96+
# Add deployment environment to show URL in GitHub UI
97+
environment:
98+
name: preview-${{ github.ref_name }}
99+
96100
steps:
101+
- name: Calculate sanitized branch name
102+
id: branch
103+
run: |
104+
SANITIZED_BRANCH=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9-]/-/g' | tr '[:upper:]' '[:lower:]')
105+
echo "sanitized=$SANITIZED_BRANCH" >> $GITHUB_OUTPUT
106+
echo "url=https://gprg-${SANITIZED_BRANCH}.surge.sh" >> $GITHUB_OUTPUT
97107
- name: Debug deployment conditions
98108
run: |
99109
echo "GitHub ref: ${{ github.ref }}"
@@ -110,13 +120,14 @@ jobs:
110120
path: ./preview-out
111121

112122
- name: Deploy to Surge.sh (Preview)
123+
id: deploy
113124
run: |
114125
npm install -g surge
115-
# Sanitize branch name for URL (replace invalid characters with dashes)
116-
SANITIZED_BRANCH=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9-]/-/g' | tr '[:upper:]' '[:lower:]')
117126
echo "Deploying preview for branch: ${{ github.ref_name }}"
118-
echo "Sanitized branch name: $SANITIZED_BRANCH"
119-
surge ./preview-out https://gprg-${SANITIZED_BRANCH}.surge.sh --token ${{ secrets.SURGE_TOKEN }}
127+
echo "Sanitized branch name: ${{ steps.branch.outputs.sanitized }}"
128+
echo "Preview URL: ${{ steps.branch.outputs.url }}"
129+
surge ./preview-out ${{ steps.branch.outputs.url }} --token ${{ secrets.SURGE_TOKEN }}
130+
echo "deployment_url=${{ steps.branch.outputs.url }}" >> $GITHUB_OUTPUT
120131
env:
121132
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
122133

@@ -125,10 +136,7 @@ jobs:
125136
uses: actions/github-script@v7
126137
with:
127138
script: |
128-
// Sanitize branch name for URL (replace invalid characters with dashes)
129-
const branchName = '${{ github.ref_name }}';
130-
const sanitizedBranch = branchName.replace(/[^a-zA-Z0-9-]/g, '-').toLowerCase();
131-
const previewUrl = `https://gprg-${sanitizedBranch}.surge.sh`;
139+
const previewUrl = '${{ steps.deploy.outputs.deployment_url }}';
132140
133141
github.rest.issues.createComment({
134142
issue_number: context.issue.number,
@@ -137,9 +145,40 @@ jobs:
137145
body: `🚀 **Preview Deployment Ready!**\n\n📱 Preview URL: ${previewUrl}\n\n*This preview will be available for 30 days.*`
138146
});
139147
148+
- name: Create deployment status
149+
uses: actions/github-script@v7
150+
with:
151+
script: |
152+
const previewUrl = '${{ steps.deploy.outputs.deployment_url }}';
153+
154+
// Create a commit status with the deployment URL
155+
github.rest.repos.createCommitStatus({
156+
owner: context.repo.owner,
157+
repo: context.repo.repo,
158+
sha: context.sha,
159+
state: 'success',
160+
target_url: previewUrl,
161+
description: `Preview deployed to ${previewUrl}`,
162+
context: 'deployment/preview'
163+
});
164+
140165
- name: Update Status Check
141166
run: |
142-
# Sanitize branch name for URL (replace invalid characters with dashes)
143-
SANITIZED_BRANCH=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9-]/-/g' | tr '[:upper:]' '[:lower:]')
144-
echo "Preview deployed successfully!"
145-
echo "Preview URL: https://gprg-${SANITIZED_BRANCH}.surge.sh"
167+
echo "🚀 Preview deployed successfully!"
168+
echo "📱 Preview URL: ${{ steps.deploy.outputs.deployment_url }}"
169+
echo ""
170+
echo "You can find this URL in:"
171+
echo "1. GitHub Actions > Environments tab"
172+
echo "2. Commit status checks"
173+
echo "3. This workflow run summary"
174+
175+
# Add to job summary for easy access
176+
echo "## 🚀 Preview Deployment Complete!" >> $GITHUB_STEP_SUMMARY
177+
echo "" >> $GITHUB_STEP_SUMMARY
178+
echo "**Branch:** \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY
179+
echo "**Preview URL:** [${{ steps.deploy.outputs.deployment_url }}](${{ steps.deploy.outputs.deployment_url }})" >> $GITHUB_STEP_SUMMARY
180+
echo "" >> $GITHUB_STEP_SUMMARY
181+
echo "### Where to find this URL:" >> $GITHUB_STEP_SUMMARY
182+
echo "- **Environments tab:** Go to your repository → Environments → preview-${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
183+
echo "- **Commit status:** Check the commit status checks for 'deployment/preview'" >> $GITHUB_STEP_SUMMARY
184+
echo "- **This summary:** Bookmark this workflow run for easy access" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)