|
1 | | -# Publish |
2 | | - |
3 | | -name: Publish |
4 | | - |
5 | | -# Controls when the workflow will run |
6 | | -on: |
7 | | - # Triggers the workflow on push event, but only for main branch |
8 | | - push: |
9 | | - branches: |
10 | | - - main |
11 | | - # Triggers the workflow on pull request event, but only for pull request from not forked repo |
12 | | - pull_request: |
13 | | - types: |
14 | | - - opened |
15 | | - - synchronize |
16 | | - # Triggers the workflow on pull request event, but only for pull request opened or pull request labeled with "🚀request-deploy" (from forked repo) |
17 | | - # pull_request is not allowed to use secrets, so we use pull_request_target instead (in forked repos) |
18 | | - pull_request_target: |
19 | | - types: |
20 | | - # When a created pull request from forked repo, it will be comment 'Should deploy to add label' |
21 | | - - opened |
22 | | - # When a labeled '🚀request-deploy' pull request from forked repo, it will be deploy to Cloudflare Pages |
23 | | - - labeled |
24 | | - # Allows you to run this workflow manually from the Actions tab |
25 | | - workflow_dispatch: |
26 | | - |
27 | | -permissions: |
28 | | - # default contents: read & write (in forked repos, only read) |
29 | | - contents: write |
30 | | - # default deployments: read & write (in forked repos, only read) |
31 | | - deployments: write |
32 | | - # default pull-requests: read & write (in forked repos, only read) |
33 | | - pull-requests: write |
34 | | - |
35 | | -# A workflow run is made up of one or more jobs that can run sequentially or in parallel |
36 | | -jobs: |
37 | | - # Deploy |
38 | | - deploy: |
39 | | - name: Deploy |
40 | | - runs-on: ${{ matrix.os }} |
41 | | - # push event in main branch |
42 | | - # workflow_dispatch event |
43 | | - # pull_request event from not forked repo |
44 | | - # pull_request_target event with label "🚀request-deploy" from forked repo |
45 | | - if: ${{ |
46 | | - github.event_name == 'push' || |
47 | | - github.event_name == 'workflow_dispatch' || |
48 | | - (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false) || |
49 | | - (github.event_name == 'pull_request_target' && |
50 | | - github.event.action == 'labeled' && |
51 | | - github.event.pull_request.head.repo.fork == true && |
52 | | - contains(github.event.label.name, '🚀request-deploy')) |
53 | | - }} |
54 | | - |
55 | | - strategy: |
56 | | - matrix: |
57 | | - os: [ubuntu-latest] |
58 | | - node: [18] |
59 | | - # Cancel previous runs that are not completed yet |
60 | | - concurrency: |
61 | | - group: ${{ github.workflow }}-${{ github.event.pull_request.head.ref || github.ref }} |
62 | | - cancel-in-progress: true |
63 | | - timeout-minutes: 10 |
64 | | - |
65 | | - steps: |
66 | | - - name: Checkout |
67 | | - uses: actions/checkout@v3 |
68 | | - with: |
69 | | - ref: ${{ github.event.pull_request.head.sha || github.ref }} |
70 | | - fetch-depth: 0 |
71 | | - |
72 | | - - name: Remove built-in Yarn |
73 | | - run: npm uninstall -g yarn |
74 | | - |
75 | | - - name: Enable Corepack |
76 | | - run: corepack enable |
77 | | - |
78 | | - - name: Setup node |
79 | | - uses: actions/setup-node@v3 |
80 | | - with: |
81 | | - node-version: ${{ matrix.node }} |
82 | | - cache: 'yarn' |
83 | | - |
84 | | - - name: Install dependencies |
85 | | - run: yarn install --check-cache |
86 | | - |
87 | | - - name: Build website |
88 | | - run: yarn build |
89 | | - |
90 | | - - name: Publish to Cloudflare Pages |
91 | | - id: cloudflare-pages-deploy |
92 | | - uses: cloudflare/pages-action@v1 |
93 | | - with: |
94 | | - accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
95 | | - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
96 | | - projectName: docusauruscommunitywebsite |
97 | | - directory: build |
98 | | - gitHubToken: ${{ secrets.GITHUB_TOKEN }} |
99 | | - |
100 | | - - name: Create commit comment |
101 | | - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} |
102 | | - uses: peter-evans/commit-comment@v2 |
103 | | - with: |
104 | | - body: | |
105 | | - ### ⚡ Successfully deployed to Cloudflare Pages! |
106 | | - | <span aria-hidden="true">🔨</span> **Latest commit** | ${{ github.event.pull_request.head.sha || github.sha }} | |
107 | | - | <span aria-hidden="true">🔍</span> **Latest deploy log** | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
108 | | - | <span aria-hidden="true">😎</span> **Deploy preview URL** | [${{ steps.cloudflare-pages-deploy.outputs.url }}](${{ steps.cloudflare-pages-deploy.outputs.url }}) | |
109 | | - | <span aria-hidden="true">🌳</span> **Environment** | ${{ steps.cloudflare-pages-deploy.outputs.environment }} | |
110 | | -
|
111 | | - - name: Create PR comment |
112 | | - if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }} |
113 | | - uses: mshick/add-pr-comment@v2 |
114 | | - with: |
115 | | - message: | |
116 | | - ### ⚡ Successfully deployed to Cloudflare Pages! |
117 | | - | <span aria-hidden="true">🔨</span> **Latest commit** | ${{ github.event.pull_request.head.sha || github.sha }} | |
118 | | - | <span aria-hidden="true">🔍</span> **Latest deploy log** | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
119 | | - | <span aria-hidden="true">😎</span> **Deploy preview URL** | [${{ steps.cloudflare-pages-deploy.outputs.url }}](${{ steps.cloudflare-pages-deploy.outputs.url }}) | |
120 | | - | <span aria-hidden="true">🌳</span> **Environment** | ${{ steps.cloudflare-pages-deploy.outputs.environment }} | |
121 | | -
|
122 | | - - name: Remove label |
123 | | - if: ${{ github.event_name == 'pull_request_target' && contains(github.event.label.name, '🚀request-deploy') }} |
124 | | - uses: actions/github-script@v6 |
125 | | - with: |
126 | | - github-token: ${{ secrets.GITHUB_TOKEN }} |
127 | | - script: | |
128 | | - github.rest.issues.removeLabel({ |
129 | | - issue_number: context.issue.number, |
130 | | - owner: context.repo.owner, |
131 | | - repo: context.repo.repo, |
132 | | - name: ['🚀request-deploy'] |
133 | | - }) |
134 | | -
|
135 | | - # Comment on PR from the fork |
136 | | - comment: |
137 | | - name: Comment |
138 | | - runs-on: ubuntu-latest |
139 | | - |
140 | | - # pull_request_target opened event from forked repo |
141 | | - if: ${{ |
142 | | - github.event_name == 'pull_request_target' && |
143 | | - github.event.action == 'opened' && |
144 | | - github.event.pull_request.head.repo.fork == true |
145 | | - }} |
146 | | - |
147 | | - steps: |
148 | | - - name: Create PR comment |
149 | | - run: | |
150 | | - cat << EOF > comment.md |
151 | | - # ⚠️ Deployments require the '🚀request-deploy' label |
152 | | -
|
153 | | - This repository is a forked repository. For security reasons, deployments from forked repositories are not automatic. |
154 | | - |
155 | | - To request a deployment, add the '🚀request-deploy' label to this pull request. (Only some members can add labels). |
156 | | - EOF |
157 | | -
|
158 | | - gh pr comment ${{ github.event.number }} -R ${{ github.repository }} -F comment.md |
159 | | - env: |
160 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 1 | +# Publish |
| 2 | + |
| 3 | +name: Publish |
| 4 | + |
| 5 | +# Controls when the workflow will run |
| 6 | +on: |
| 7 | + # Triggers the workflow on push event, but only for main branch |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + # Triggers the workflow on pull request event, but only for pull request from not forked repo |
| 12 | + pull_request: |
| 13 | + types: |
| 14 | + - opened |
| 15 | + - synchronize |
| 16 | + # Triggers the workflow on pull request event, but only for pull request opened or pull request labeled with "🚀request-deploy" (from forked repo) |
| 17 | + # pull_request is not allowed to use secrets, so we use pull_request_target instead (in forked repos) |
| 18 | + pull_request_target: |
| 19 | + types: |
| 20 | + # When a created pull request from forked repo, it will be comment 'Should deploy to add label' |
| 21 | + - opened |
| 22 | + # When a labeled '🚀request-deploy' pull request from forked repo, it will be deploy to Cloudflare Pages |
| 23 | + - labeled |
| 24 | + # Allows you to run this workflow manually from the Actions tab |
| 25 | + workflow_dispatch: |
| 26 | + |
| 27 | +permissions: |
| 28 | + # default contents: read & write (in forked repos, only read) |
| 29 | + contents: write |
| 30 | + # default deployments: read & write (in forked repos, only read) |
| 31 | + deployments: write |
| 32 | + # default pull-requests: read & write (in forked repos, only read) |
| 33 | + pull-requests: write |
| 34 | + |
| 35 | +# A workflow run is made up of one or more jobs that can run sequentially or in parallel |
| 36 | +jobs: |
| 37 | + # Deploy |
| 38 | + deploy: |
| 39 | + name: Deploy |
| 40 | + runs-on: ${{ matrix.os }} |
| 41 | + # push event in main branch |
| 42 | + # workflow_dispatch event |
| 43 | + # pull_request event from not forked repo |
| 44 | + # pull_request_target event with label "🚀request-deploy" from forked repo |
| 45 | + if: ${{ |
| 46 | + github.event_name == 'push' || |
| 47 | + github.event_name == 'workflow_dispatch' || |
| 48 | + (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false) || |
| 49 | + (github.event_name == 'pull_request_target' && |
| 50 | + github.event.action == 'labeled' && |
| 51 | + github.event.pull_request.head.repo.fork == true && |
| 52 | + contains(github.event.label.name, '🚀request-deploy')) |
| 53 | + }} |
| 54 | + |
| 55 | + strategy: |
| 56 | + matrix: |
| 57 | + os: [ubuntu-latest] |
| 58 | + node: [current] |
| 59 | + # Cancel previous runs that are not completed yet |
| 60 | + concurrency: |
| 61 | + group: ${{ github.workflow }}-${{ github.event.pull_request.head.ref || github.ref }} |
| 62 | + cancel-in-progress: true |
| 63 | + timeout-minutes: 10 |
| 64 | + |
| 65 | + steps: |
| 66 | + - name: Checkout |
| 67 | + uses: actions/checkout@v6 |
| 68 | + with: |
| 69 | + ref: ${{ github.event.pull_request.head.sha || github.ref }} |
| 70 | + fetch-depth: 0 |
| 71 | + |
| 72 | + - name: Remove built-in Yarn |
| 73 | + run: npm uninstall -g yarn |
| 74 | + |
| 75 | + - name: Enable Corepack |
| 76 | + run: corepack enable |
| 77 | + |
| 78 | + - name: Setup node |
| 79 | + uses: actions/setup-node@v6 |
| 80 | + with: |
| 81 | + node-version: ${{ matrix.node }} |
| 82 | + cache: 'yarn' |
| 83 | + |
| 84 | + - name: Install dependencies |
| 85 | + run: yarn install --check-cache |
| 86 | + |
| 87 | + - name: Build website |
| 88 | + run: yarn build |
| 89 | + |
| 90 | + - name: Publish to Cloudflare Pages |
| 91 | + id: cloudflare-pages-deploy |
| 92 | + uses: cloudflare/wrangler-action@v4 |
| 93 | + with: |
| 94 | + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 95 | + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 96 | + command: 'pages deploy build --project-name=halocommunitywebsite' |
| 97 | + gitHubToken: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + |
| 99 | + - name: Create commit comment |
| 100 | + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} |
| 101 | + uses: peter-evans/commit-comment@v4 |
| 102 | + with: |
| 103 | + body: | |
| 104 | + ### ⚡ Successfully deployed to Cloudflare Pages! |
| 105 | + | <span aria-hidden="true">🔨</span> **Latest commit** | ${{ github.event.pull_request.head.sha || github.sha }} | |
| 106 | + | <span aria-hidden="true">🔍</span> **Latest deploy log** | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| 107 | + | <span aria-hidden="true">😎</span> **Deploy preview URL** | [${{ steps.cloudflare-pages-deploy.outputs.url }}](${{ steps.cloudflare-pages-deploy.outputs.url }}) | |
| 108 | + | <span aria-hidden="true">🌳</span> **Environment** | ${{ steps.cloudflare-pages-deploy.outputs.environment }} | |
| 109 | +
|
| 110 | + - name: Create PR comment |
| 111 | + if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }} |
| 112 | + uses: mshick/add-pr-comment@v3 |
| 113 | + with: |
| 114 | + message: | |
| 115 | + ### ⚡ Successfully deployed to Cloudflare Pages! |
| 116 | + | <span aria-hidden="true">🔨</span> **Latest commit** | ${{ github.event.pull_request.head.sha || github.sha }} | |
| 117 | + | <span aria-hidden="true">🔍</span> **Latest deploy log** | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| 118 | + | <span aria-hidden="true">😎</span> **Deploy preview URL** | [${{ steps.cloudflare-pages-deploy.outputs.url }}](${{ steps.cloudflare-pages-deploy.outputs.url }}) | |
| 119 | + | <span aria-hidden="true">🌳</span> **Environment** | ${{ steps.cloudflare-pages-deploy.outputs.environment }} | |
| 120 | +
|
| 121 | + - name: Remove label |
| 122 | + if: ${{ github.event_name == 'pull_request_target' && contains(github.event.label.name, '🚀request-deploy') }} |
| 123 | + uses: actions/github-script@v8 |
| 124 | + with: |
| 125 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 126 | + script: | |
| 127 | + github.rest.issues.removeLabel({ |
| 128 | + issue_number: context.issue.number, |
| 129 | + owner: context.repo.owner, |
| 130 | + repo: context.repo.repo, |
| 131 | + name: ['🚀request-deploy'] |
| 132 | + }) |
| 133 | +
|
| 134 | + # Comment on PR from the fork |
| 135 | + comment: |
| 136 | + name: Comment |
| 137 | + runs-on: ubuntu-latest |
| 138 | + |
| 139 | + # pull_request_target opened event from forked repo |
| 140 | + if: ${{ |
| 141 | + github.event_name == 'pull_request_target' && |
| 142 | + github.event.action == 'opened' && |
| 143 | + github.event.pull_request.head.repo.fork == true |
| 144 | + }} |
| 145 | + |
| 146 | + steps: |
| 147 | + - name: Create PR comment |
| 148 | + run: | |
| 149 | + cat << EOF > comment.md |
| 150 | + # ⚠️ Deployments require the '🚀request-deploy' label |
| 151 | +
|
| 152 | + This repository is a forked repository. For security reasons, deployments from forked repositories are not automatic. |
| 153 | + |
| 154 | + To request a deployment, add the '🚀request-deploy' label to this pull request. (Only some members can add labels). |
| 155 | + EOF |
| 156 | +
|
| 157 | + gh pr comment ${{ github.event.number }} -R ${{ github.repository }} -F comment.md |
| 158 | + env: |
| 159 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments