-
Notifications
You must be signed in to change notification settings - Fork 196
138 lines (116 loc) · 3.86 KB
/
pull_request.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Pull request workflow
on:
pull_request:
branches:
- '*'
jobs:
typos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: crate-ci/typos@master
test-deploy:
name: Test deploy
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
node-version: 16
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: 16
- name: Install node_modules
run: yarn
- name: Generate Site
run: yarn generate
- name: "Upload generated content"
uses: actions/upload-artifact@v2
with:
name: starknet-site
if-no-files-found: error
path:
public_html
publish:
name: deploy-review
runs-on: ubuntu-latest
needs:
- test-deploy
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
node-version: 16
ref: gh-pages
USER_TOKEN: ${{ secrets.USER_TOKEN }}
- name: Extract PR details
id: pr
run: |
PR_ID=pr-${{ github.event.pull_request.number }}
PREVIEW_PATH=previews/${PR_ID}
echo "::set-output name=PR_ID::${PR_ID}"
- name: "Remove preview build directory"
run: rm -rf ${{ steps.pr.outputs.PR_ID }}
- name: "Create preview build directory"
run: mkdir -p ${{ steps.pr.outputs.PR_ID }}
- name: "Download generated content"
uses: actions/download-artifact@v2
with:
name: starknet-site
path: ${{ steps.pr.outputs.PR_ID }}
- name: PR preview details
run:
echo "you can preview the PR at https://starknet-io.github.io/starknet-docs/${{ steps.pr.outputs.PR_ID }}/documentation/"
- name: "Commit changes"
run: |
set -euo pipefail
# Debug information
echo "Current directory: $(pwd)"
echo "Contents of the repository:"
ls -al
echo "Git status:"
git status
git config user.name "GitHub Actions"
git config user.email [email protected]
git add .
if ! git diff-index --quiet HEAD --; then
# Debug information
echo "Changes detected. Committing and pushing changes."
commit_message="Adding or updating preview build for PR ${{ steps.pr.outputs.PR_ID }}"
# Debug message
echo "Commit message: $commit_message"
# Commit changes
git commit -m "$commit_message"
# Check if commit was successful
if [ $? -eq 0 ]; then
# Debug information
echo "Commit successful. Pushing changes."
# Push changes
git push --set-upstream origin gh-pages
# Check if push was successful
if [ $? -eq 0 ]; then
# Debug information
echo "Push successful."
else
# Debug information
echo "Error: Push failed."
fi
else
# Debug information
echo "Error: Commit failed."
fi
else
# Debug information
echo "No changes found."
fi
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: "Send comment to PR"
continue-on-error: true
run: |
set -euo pipefail
echo "Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/${{ steps.pr.outputs.PR_ID }}/documentation/ ." >/tmp/comment
gh pr comment ${{ github.event.pull_request.number }} -F /tmp/comment
env:
GH_TOKEN: "${{ github.token }}"