Skip to content

Commit 4e77497

Browse files
authored
Merge pull request #488 from citation-file-format/preview-netlify
2 parents 0f23f25 + ad90d5e commit 4e77497

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

.github/workflows/preview.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Preview
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
jobs:
13+
preview:
14+
if: github.repository_owner == 'citation-file-format'
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
with:
19+
ref: ${{ github.head_ref }}
20+
- name: Use Node.js 14
21+
uses: actions/setup-node@v2
22+
with:
23+
node-version: '14'
24+
cache: 'npm'
25+
- name: Run npm clean-install
26+
run: npm clean-install
27+
- name: Run build on PR
28+
run: |
29+
if [[ ${{ github.event_name }} == "pull_request" ]]; then
30+
export PUBLICPATH=PR${{ github.event.number }}
31+
else
32+
export PUBLICPATH=main
33+
fi
34+
echo "PUBLICPATH=$PUBLICPATH" >> $GITHUB_ENV
35+
sed -i "s|publicPath: 'cff-initializer-javascript'|publicPath: '$PUBLICPATH'|" quasar.conf.js
36+
npm run build
37+
- name: Deploy to gh-preview
38+
uses: peaceiris/actions-gh-pages@v3
39+
with:
40+
github_token: ${{ secrets.GITHUB_TOKEN }}
41+
publish_branch: gh-preview
42+
destination_dir: "${{ env.PUBLICPATH }}"
43+
publish_dir: ./dist
44+
user_name: 'cffinit[bot]'
45+
user_email: 'cffinit[bot]@users.noreply.github.com'
46+
commit_message: ':robot: Create preview of ${{ env.PUBLICPATH }}'
47+
pr_comment:
48+
if: github.event_name == 'pull_request' && github.repository_owner == 'citation-file-format'
49+
needs: preview
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: 'Comment PR'
53+
uses: actions/github-script@0.3.0
54+
with:
55+
github-token: ${{ secrets.GITHUB_TOKEN }}
56+
script: |
57+
const { issue: { number: issue_number }, repo: { owner, repo } } = context;
58+
github.issues.createComment({ issue_number, owner, repo, body: 'Once the build has completed, you can preview your PR at this URL: https://cffinit.netlify.app/PR${{ github.event.number }}/' });
59+

0 commit comments

Comments
 (0)