Skip to content

Commit 2e640f0

Browse files
docs: update GitHub Actions workflow to support pull requests from 'dev' branch and add Netlify deployment steps (#46)
* docs: update GitHub Actions workflow to support pull requests from 'dev' branch and add Netlify deployment steps * fix: correct syntax in Netlify deploy command in docs-preview workflow * fix: escape message string in Netlify deploy command in docs-preview workflow * fix: update issue number reference in deployment comment to use pull request number * fix: update permissions for pull requests and correct issue number reference in deployment comment * fix: enhance Netlify deployment workflow to check for existing comments and update accordingly * fix: correct deployment comment body format in Netlify workflow * fix: update Netlify deployment workflow to use dynamic alias for deployment URLs * fix: sanitize NETLIFY_ALIAS variable in deployment workflow * fix: update NETLIFY_ALIAS variable to use base SHA for deployment URLs * feat: add devcontainer and vscode settings for mise development environment * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * chore: remove unused devcontainer and vscode settings files fix: update NETLIFY_ALIAS to use the first 8 characters of the commit SHA * fix: update NETLIFY_ALIAS to use pull request number for deployment --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 1f1bdf7 commit 2e640f0

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

.github/workflows/docs-preview.yml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ name: Preview Docs
33
on:
44
workflow_dispatch: # Allows manual triggering of the workflow
55
pull_request:
6-
branches: ["main"] # Triggers on pull requests targeting the main branch
6+
branches: ["main", "dev"] # Triggers on pull requests targeting the main or dev branches
77
paths: # Only triggers if specific files or directories are changed
88
- "docs/**"
99
- "mise.toml"
1010
- "mkdocs.yml"
1111
- "requirements.txt"
12+
permissions:
13+
pull-requests: write # Required for commenting on pull requests
1214
jobs:
1315
deploy:
1416
runs-on: ubuntu-latest
1517
timeout-minutes: 10
18+
env:
19+
NETLIFY_ALIAS: ${{ github.event.number }} # Unique alias for the deployment
1620
steps:
1721
# Step 1: Check out the repository
1822
# Description: Checks out the repository so that the workflow can access its contents.
@@ -26,3 +30,43 @@ jobs:
2630
# Description: Runs the style:lint, style:format, and docs:build commands using mise.
2731
- name: Build docs
2832
run: mise run docs:build
33+
# Step 4: Deploy to Netlify
34+
# Description: Deploys the built documentation to Netlify using the netlify-cli.
35+
# Note: The site ID and authentication token are provided as secrets for security.
36+
- name: Deploy to Netlify
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub token for authentication
39+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} # Netlify site ID
40+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} # Netlify authentication token
41+
MESSAGE: "#${{ github.event.number }}: ${{ github.event.pull_request.title }}"
42+
run: "netlify deploy --dir ./site/ --alias ${{ env.NETLIFY_ALIAS }} --message \"${{ env.MESSAGE }}\" --site ${{ secrets.NETLIFY_SITE_ID }} --auth ${{ secrets.NETLIFY_AUTH_TOKEN }} --timeout=60"
43+
# Step 5: Find existing comment
44+
# Description: Uses the find-comment action to check if a comment from the GitHub Actions bot already exists.
45+
# Note: The comment is identified by the presence of a specific body text.
46+
- name: Find Comment
47+
uses: peter-evans/find-comment@v3
48+
id: fc
49+
with:
50+
issue-number: ${{ github.event.number }}
51+
comment-author: 'github-actions[bot]'
52+
body-includes: ":rocket: Deployed on https://"
53+
# Step 6: Comment on the pull request with the deployment URL
54+
# Description: Uses the create-or-update-comment action to post a comment on the pull request with the deployment URL.
55+
# Note: The URL is constructed using the pull request number and the Netlify site alias.
56+
- name: Comment Deployment URL
57+
if: steps.fc.outputs.comment-id == ''
58+
uses: peter-evans/create-or-update-comment@v4
59+
with:
60+
issue-number: ${{ github.event.number }}
61+
body: ":rocket: Deployed on https://${{ env.NETLIFY_ALIAS }}--fastapi-turkiye-docs-preview.netlify.app" # Use the variable
62+
# Step 7: Update the existing comment if it exists
63+
# Description: If a comment already exists, update it with the new deployment URL.
64+
# Note: The comment ID is retrieved from the steps.fc output.
65+
- name: Update Deployment URL
66+
if: steps.fc.outputs.comment-id != ''
67+
uses: peter-evans/create-or-update-comment@v4
68+
with:
69+
comment-id: ${{ steps.fc.outputs.comment-id }}
70+
issue-number: ${{ github.event.number }}
71+
body: ":rocket: Deployed on https://${{ env.NETLIFY_ALIAS }}--fastapi-turkiye-docs-preview.netlify.app" # Use the variable
72+
edit-mode: replace

mise.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ yamllint = "1.37.0"
99
pre-commit = "4.1.0"
1010
taplo = "0.9.3"
1111
"pipx:mkdocs" = { version = "1.6.1", extras = "i18n", uvx_args = "--with-requirements requirements.txt" }
12+
"npm:netlify-cli" = "19.1.5"
1213

1314
[tasks."style:lint"]
1415
description = "Linting"

0 commit comments

Comments
 (0)