|
1 | 1 | name: Deploy
|
2 | 2 |
|
3 |
| -on: |
4 |
| - push: |
5 |
| - branches: |
6 |
| - - main |
7 |
| - pull_request: |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: [Build] |
| 6 | + types: |
| 7 | + - completed |
8 | 8 |
|
9 | 9 | jobs:
|
10 |
| - build: |
11 |
| - uses: ./.github/workflows/build.yml |
12 |
| - secrets: inherit |
13 |
| - |
14 | 10 | deploy_live_website:
|
15 | 11 | runs-on: ubuntu-latest
|
16 |
| - needs: build |
17 |
| - if: github.event_name == 'push' |
| 12 | + if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' |
18 | 13 | steps:
|
19 |
| - - name: Checkout |
20 |
| - uses: actions/checkout@v4 |
| 14 | + - name: Checkout repository |
| 15 | + uses: actions/checkout@v3 |
21 | 16 |
|
22 | 17 | - name: Download pages
|
23 | 18 | uses: actions/download-artifact@v4
|
24 | 19 | with:
|
25 |
| - name: page-build |
| 20 | + run-id: ${{ github.event.workflow_run.id }} |
| 21 | + github-token: ${{ github.token }} |
| 22 | + merge-multiple: true |
26 | 23 | path: public
|
27 | 24 |
|
28 |
| - - name: Get PR information |
29 |
| - uses: potiuk/get-workflow-origin@751d47254ef9e8b5eef955e24e79305233702781 |
30 |
| - id: source-run-info |
31 |
| - with: |
32 |
| - token: ${{ secrets.GITHUB_TOKEN }} |
33 |
| - sourceRunId: ${{ github.event.workflow_run.id }} |
34 |
| - |
35 | 25 | - name: change URLs for large files
|
36 | 26 | shell: bash
|
37 |
| - run: | |
38 |
| - sed -i 's|search/search_index.json|https://storage.googleapis.com/cp-algorithms/search_index.json|g' public/assets/javascripts/*.js |
| 27 | + run: sed -i 's|search/search_index.json|https://storage.googleapis.com/cp-algorithms/search_index.json|g' public/assets/javascripts/*.js |
39 | 28 |
|
40 |
| - - id: 'auth' |
41 |
| - uses: 'google-github-actions/auth@v2.1.6' |
| 29 | + - id: auth |
| 30 | + uses: google-github-actions/auth@v2.1.6 |
42 | 31 | with:
|
43 | 32 | credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
|
44 | 33 |
|
45 |
| - - uses: 'google-github-actions/upload-cloud-storage@v1' |
| 34 | + - uses: google-github-actions/upload-cloud-storage@v1 |
46 | 35 | with:
|
47 |
| - path: 'public/search/search_index.json' |
48 |
| - destination: 'cp-algorithms' |
| 36 | + path: public/search/search_index.json |
| 37 | + destination: cp-algorithms |
49 | 38 |
|
50 | 39 | - uses: FirebaseExtended/action-hosting-deploy@v0
|
51 | 40 | id: firebase-deploy
|
52 |
| - if: env.FIREBASE_SERVICE_ACCOUNT |
53 |
| - env: |
54 |
| - LIVE_NAME: "live" |
55 |
| - FIREBASE_SERVICE_ACCOUNT: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }} |
56 | 41 | with:
|
57 |
| - repoToken: "${{ secrets.GITHUB_TOKEN }}" |
58 |
| - firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}" |
| 42 | + repoToken: ${{ github.token }} |
| 43 | + firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }} |
59 | 44 | projectId: cp-algorithms
|
60 |
| - channelId: ${{ env.LIVE_NAME }} |
| 45 | + channelId: live |
61 | 46 |
|
62 | 47 | deploy_github_pages:
|
63 | 48 | runs-on: ubuntu-latest
|
64 |
| - needs: build |
| 49 | + if: github.event.workflow_run.conclusion == 'success' |
65 | 50 | steps:
|
66 | 51 | - name: Checkout repository
|
67 | 52 | uses: actions/checkout@v3
|
68 | 53 |
|
69 |
| - - name: Download artifact |
| 54 | + - name: Download pages |
70 | 55 | uses: actions/download-artifact@v4
|
71 | 56 | with:
|
72 |
| - name: page-build |
| 57 | + run-id: ${{ github.event.workflow_run.id }} |
| 58 | + github-token: ${{ github.token }} |
73 | 59 | path: public
|
74 | 60 |
|
| 61 | + - name: Get PR number from artifact |
| 62 | + id: get-pr-number |
| 63 | + run: echo "pr_number=$(ls public)" >> $GITHUB_OUTPUT |
| 64 | + |
75 | 65 | - name: Configure git
|
76 | 66 | run: |
|
77 | 67 | git config --global user.name "github-actions[bot]"
|
78 | 68 | git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
79 |
| -
|
| 69 | + |
80 | 70 | - name: Deploy to gh-pages
|
81 | 71 | uses: peaceiris/actions-gh-pages@v3
|
82 | 72 | with:
|
83 |
| - github_token: ${{ secrets.GITHUB_TOKEN }} |
84 |
| - publish_dir: ./public |
| 73 | + github_token: ${{ github.token }} |
| 74 | + publish_dir: public/${{ steps.get-pr-number.outputs.pr_number }} |
85 | 75 | publish_branch: gh-pages
|
86 |
| - destination_dir: ${{ github.event.pull_request.number || 'main' }}/ |
| 76 | + destination_dir: ${{ steps.get-pr-number.outputs.pr_number }} |
87 | 77 |
|
88 |
| - - name: Update or create preview comment |
89 |
| - if: github.event_name == 'pull_request' |
90 |
| - uses: actions/github-script@v6 |
| 78 | + - name: Create or update PR comment |
| 79 | + if: steps.get-pr-number.outputs.pr_number != 'main' |
| 80 | + uses: peter-evans/create-or-update-comment@v3 |
91 | 81 | with:
|
92 |
| - script: | |
93 |
| - const prNumber = ${{ github.event.pull_request.number }}; |
94 |
| - const repo = context.repo.repo; |
95 |
| - const owner = context.repo.owner; |
96 |
| - const commitSha = context.payload.pull_request.head.sha; |
97 |
| - const baseUrl = `https://${owner}.github.io/${repo}/`; |
98 |
| - const previewUrl = `${baseUrl}${prNumber}/`; |
99 |
| - const body = `Preview the changes for PR #${prNumber} (${commitSha}) here: [${previewUrl}](${previewUrl})`; |
100 |
| - |
101 |
| - // Retrieve comments for the PR to check if the comment already exists |
102 |
| - const { data: comments } = await github.rest.issues.listComments({ |
103 |
| - owner: owner, |
104 |
| - repo: repo, |
105 |
| - issue_number: prNumber, |
106 |
| - }); |
107 |
| - |
108 |
| - // Look for an existing comment with the preview link |
109 |
| - const existingComment = comments.find(comment => comment.body.includes('Preview the changes for PR')); |
110 |
| - |
111 |
| - if (existingComment) { |
112 |
| - // Update the existing comment |
113 |
| - await github.rest.issues.updateComment({ |
114 |
| - owner: owner, |
115 |
| - repo: repo, |
116 |
| - comment_id: existingComment.id, |
117 |
| - body: body, |
118 |
| - }); |
119 |
| - } else { |
120 |
| - // Create a new comment |
121 |
| - await github.rest.issues.createComment({ |
122 |
| - issue_number: prNumber, |
123 |
| - owner: owner, |
124 |
| - repo: repo, |
125 |
| - body: body, |
126 |
| - }); |
127 |
| - } |
| 82 | + token: ${{ github.token }} |
| 83 | + issue-number: ${{ steps.get-pr-number.outputs.pr_number }} |
| 84 | + body: 'Preview the changes for PR #${{ steps.get-pr-number.outputs.pr_number }} at https://gh.cp-algorithms.com/${{ steps.get-pr-number.outputs.pr_number }}/ (current version: ${{ github.event.workflow_run.head_sha }}).' |
| 85 | + body-includes: 'Preview the changes for PR' |
| 86 | + mode: replace |
0 commit comments