@@ -2,97 +2,96 @@ name: Deploy
2
2
3
3
on :
4
4
workflow_run :
5
- # `workflow_run` events have access to secrets
6
5
workflows :[Build]
7
6
types :
8
7
-completed
9
8
10
9
jobs :
11
10
deploy_live_website :
12
11
runs-on :ubuntu-latest
13
- if :>
14
- ${{ github.event.workflow_run.event == 'pull_request' &&
15
- github.event.workflow_run.conclusion == 'success' }}
12
+ if :github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push'
16
13
steps :
17
- -name :" Get PR information"
18
- uses :potiuk/get-workflow-origin@751d47254ef9e8b5eef955e24e79305233702781
19
- id :source-run-info
20
- with :
21
- token :${{ secrets.GITHUB_TOKEN }}
22
- sourceRunId :${{ github.event.workflow_run.id }}
23
-
24
14
-name :Checkout repository
25
- uses :actions/checkout@v3
15
+ uses :actions/checkout@v4
26
16
27
- -name :' Download artifact '
28
- uses :actions/ github-script@v6
17
+ -name :Attach run to the commit
18
+ uses :./. github/actions/set-commit-status
29
19
with :
30
- script :|
31
- let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
32
- owner: context.repo.owner,
33
- repo: context.repo.repo,
34
- run_id: context.payload.workflow_run.id,
35
- });
36
- let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
37
- return artifact.name == "page-build"
38
- })[0];
39
- let download = await github.rest.actions.downloadArtifact({
40
- owner: context.repo.owner,
41
- repo: context.repo.repo,
42
- artifact_id: matchArtifact.id,
43
- archive_format: 'zip',
44
- });
45
- let fs = require('fs');
46
- fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/page-build.zip`, Buffer.from(download.data));
20
+ sha :${{ github.event.workflow_run.head_sha }}
21
+ status :pending
47
22
48
- -run :|
49
- unzip page-build.zip -d public
23
+ -name :Download pages
24
+ uses :actions/download-artifact@v4
25
+ with :
26
+ run-id :${{ github.event.workflow_run.id }}
27
+ github-token :${{ github.token }}
28
+ merge-multiple :true
29
+ path :public
50
30
51
31
-name :change URLs for large files
52
- if :${{ steps.source-run-info.outputs.sourceEvent == 'push' && steps.source-run-info.outputs.targetBranch == 'master'}}
53
32
shell :bash
54
- run :|
55
- sed -i 's|search/search_index.json|https://storage.googleapis.com/cp-algorithms/search_index.json|g' public/assets/javascripts/*.js
33
+ run :sed -i 's|search/search_index.json|https://storage.googleapis.com/cp-algorithms/search_index.json|g' public/assets/javascripts/*.js
56
34
57
- -id :' auth'
58
- if :${{ steps.source-run-info.outputs.sourceEvent == 'push' && steps.source-run-info.outputs.targetBranch == 'master'}}
59
- uses :' google-github-actions/auth@v0'
35
+ -id :auth
36
+ uses :google-github-actions/auth@v2.1.6
60
37
with :
61
38
credentials_json :' ${{ secrets.GCP_CREDENTIALS }}'
62
39
63
- -uses :' google-github-actions/upload-cloud-storage@v1'
64
- if :${{ steps.source-run-info.outputs.sourceEvent == 'push' && steps.source-run-info.outputs.targetBranch == 'master'}}
40
+ -uses :google-github-actions/upload-cloud-storage@v2.2.0
65
41
with :
66
- path :' public/search/search_index.json'
67
- destination :' cp-algorithms'
42
+ path :public/search/search_index.json
43
+ destination :cp-algorithms
68
44
69
45
-uses :FirebaseExtended/action-hosting-deploy@v0
70
46
id :firebase-deploy
71
- if :env.FIREBASE_SERVICE_ACCOUNT
72
- env :
73
- PREVIEW_NAME :" preview-${{ steps.source-run-info.outputs.pullRequestNumber }}"
74
- LIVE_NAME :" live"
75
- FIREBASE_SERVICE_ACCOUNT :${{ secrets.FIREBASE_SERVICE_ACCOUNT }}
76
47
with :
77
- repoToken :" ${{secrets.GITHUB_TOKEN }}"
78
- firebaseServiceAccount :" ${{ secrets.FIREBASE_SERVICE_ACCOUNT }}"
48
+ repoToken :${{github.token }}
49
+ firebaseServiceAccount :${{ secrets.FIREBASE_SERVICE_ACCOUNT }}
79
50
projectId :cp-algorithms
80
- channelId :${{ steps.source-run-info.outputs.sourceEvent == 'push' && steps.source-run-info.outputs.targetBranch == 'master' && env.LIVE_NAME || env.PREVIEW_NAME }}
51
+ channelId :live
81
52
82
- -name :comment URL to PR
83
- if : ${{ steps.source-run-info.outputs.sourceEvent == 'pull_request' }}
84
- uses : actions/github-script@v6
53
+ -name :Set final commit status
54
+ uses : ./.github/actions/set-commit-status
55
+ if : always()
85
56
with :
86
- script :|
87
- const body = `Visit the preview URL for this PR (for commit ${{ steps.source-run-info.outputs.sourceHeadSha }}):
57
+ sha :${{ github.event.workflow_run.head_sha }}
88
58
89
- ${{ steps.firebase-deploy.outputs.details_url }}
59
+ deploy_github_pages :
60
+ runs-on :ubuntu-latest
61
+ if :github.event.workflow_run.conclusion == 'success'
62
+ steps :
63
+ -name :Checkout repository
64
+ uses :actions/checkout@v4
90
65
91
- (expires ${{ steps.firebase-deploy.outputs.expire_time }})`;
66
+ -name :Attach run to the commit
67
+ uses :./.github/actions/set-commit-status
68
+ with :
69
+ sha :${{ github.event.workflow_run.head_sha }}
70
+ status :pending
92
71
93
- github.rest.issues.createComment({
94
- issue_number: ${{ steps.source-run-info.outputs.pullRequestNumber }},
95
- owner: context.repo.owner,
96
- repo: context.repo.repo,
97
- body: body
98
- })
72
+ -name :Download pages
73
+ uses :actions/download-artifact@v4
74
+ with :
75
+ run-id :${{ github.event.workflow_run.id }}
76
+ github-token :${{ github.token }}
77
+ path :public
78
+
79
+ -name :Get PR number from artifact
80
+ id :get-pr-number
81
+ run :echo "pr_number=$(ls public)" >> $GITHUB_OUTPUT
82
+
83
+ -name :Deploy to gh-pages
84
+ uses :peaceiris/actions-gh-pages@v4
85
+ with :
86
+ github_token :${{ github.token }}
87
+ user_name :github-actions[bot]
88
+ user_email :github-actions[bot]@users.noreply.github.com
89
+ publish_dir :public/${{ steps.get-pr-number.outputs.pr_number }}
90
+ destination_dir :${{ steps.get-pr-number.outputs.pr_number }}
91
+ full_commit_message :" Preview for ${{ steps.get-pr-number.outputs.pr_number != 'main' && '#' || '' }}${{ steps.get-pr-number.outputs.pr_number }} (${{ github.event.workflow_run.head_sha }}) at https://gh.cp-algorithms.com/${{ steps.get-pr-number.outputs.pr_number }}/"
92
+
93
+ -name :Set final commit status
94
+ uses :./.github/actions/set-commit-status
95
+ if :always()
96
+ with :
97
+ sha :${{ github.event.workflow_run.head_sha }}