|
1 | 1 | name: preview-env-fork-setup-update
|
2 | 2 |
|
3 | 3 | on:
|
4 |
| - workflow_run: |
5 |
| - workflows: ["check-label-preview-env"] |
6 |
| - types: [completed] |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + PR_NUMBER: |
| 7 | + type: number |
| 8 | + required: true |
| 9 | + TRIGGERING_ACTOR: |
| 10 | + type: string |
| 11 | + required: true |
| 12 | + COMMIT_SHA: |
| 13 | + type: string |
| 14 | + required: true |
7 | 15 |
|
8 | 16 | jobs:
|
9 | 17 | deploy:
|
10 |
| - runs-on: ubuntu-latest |
11 |
| - if: ${{ github.event.workflow_run.conclusion == 'success' }} |
12 |
| - steps: |
13 |
| - - name: Download PR number artifact |
14 |
| - uses: dawidd6/action-download-artifact@0c49384d39ceb023b8040f480a25596fd6cf441b # v2.26.0 |
15 |
| - with: |
16 |
| - workflow: ${{ github.event.workflow_run.workflow_id }} |
17 |
| - name: pr.txt |
18 |
| - - name: Save PR number |
19 |
| - id: pr |
20 |
| - run: | |
21 |
| - echo "::set-output name=id::$(<pr.txt)" |
22 |
| - - name: Check label |
23 |
| - uses: actions/github-script@6f00a0b667f9463337970371ccda9072ee86fb27 # v6.4.1 |
24 |
| - id: label-checker |
25 |
| - with: |
26 |
| - github-token: ${{secrets.GITHUB_TOKEN}} |
27 |
| - script: | |
28 |
| - let fs = require('fs'); |
29 |
| - let issue_number = Number(fs.readFileSync('./pr.txt')); |
30 |
| - const query = `query($owner:String!, $name:String!, $pr:Int!) { |
31 |
| - repository(owner:$owner, name:$name){ |
32 |
| - pullRequest(number:$pr) { |
33 |
| - labels(first:50) { |
34 |
| - nodes{ |
35 |
| - name |
36 |
| - } |
37 |
| - } |
38 |
| - } |
39 |
| - } |
40 |
| - }`; |
41 |
| - const variables = { |
42 |
| - owner: 'mattermost', |
43 |
| - name: 'docs', |
44 |
| - pr: issue_number |
45 |
| - }; |
46 |
| - const result = await github.graphql(query, variables); |
47 |
| - console.log(result.repository.pullRequest.labels.nodes); |
48 |
| - const labels = result.repository.pullRequest.labels.nodes; |
49 |
| - for (var index = 0; index < labels.length; ++index) { |
50 |
| - var label = labels[index]; |
51 |
| - if(label.name == 'preview-environment') { |
52 |
| - return true; |
53 |
| - } |
54 |
| - } |
55 |
| - return false; |
56 |
| -
|
57 |
| - - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 |
58 |
| - if: ${{ steps.label-checker.outputs.result == 'true' }} |
59 |
| - with: |
60 |
| - ref: ${{ github.event.workflow_run.head_sha }} |
61 |
| - token: ${{ secrets.GITHUB_TOKEN }} |
62 |
| - submodules: true |
63 |
| - fetch-depth: 0 |
64 |
| - |
65 |
| - - name: Setup Python |
66 |
| - if: ${{ steps.label-checker.outputs.result == 'true' }} |
67 |
| - uses: actions/setup-python@db9987b4c1f10f0404fa60ee629f675fafbd6763 # v4.6.0 |
68 |
| - with: |
69 |
| - python-version: '3.9' |
70 |
| - |
71 |
| - - name: Install pipenv |
72 |
| - if: ${{ steps.label-checker.outputs.result == 'true' }} |
73 |
| - run: pip install pipenv |
74 |
| - |
75 |
| - - name: Install dependencies |
76 |
| - if: ${{ steps.label-checker.outputs.result == 'true' }} |
77 |
| - run: pipenv install --dev |
78 |
| - |
79 |
| - - name: Build |
80 |
| - if: ${{ steps.label-checker.outputs.result == 'true' }} |
81 |
| - run: make SPHINXOPTS="-j auto -D html_baseurl=http://mattermost-docs-preview-pulls.s3-website-us-east-1.amazonaws.com/${{ steps.pr.outputs.id }}" html |
82 |
| - |
83 |
| - - uses: shallwefootball/s3-upload-action@4350529f410221787ccf424e50133cbc1b52704e # v1.3.3 |
84 |
| - name: Upload Preview Env |
85 |
| - if: ${{ steps.label-checker.outputs.result == 'true' }} |
86 |
| - with: |
87 |
| - aws_key_id: ${{ secrets.AWS_KEY_ID }} |
88 |
| - aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
89 |
| - aws_bucket: ${{ secrets.AWS_BUCKET }} |
90 |
| - source_dir: ./build/html |
91 |
| - destination_dir: ${{ steps.pr.outputs.id }} |
92 |
| - |
93 |
| - - name: Add comment to PR |
94 |
| - uses: peter-evans/create-or-update-comment@7dfe4b0aa0c4bbd06d172692ff8a9e18381d6979 # v3.0.1 |
95 |
| - if: ${{ success() && steps.label-checker.outputs.result == 'true' }} |
96 |
| - with: |
97 |
| - token: ${{ secrets.GITHUB_TOKEN }} |
98 |
| - issue-number: ${{ steps.pr.outputs.id }} |
99 |
| - body: | |
100 |
| - Newest code from ${{ github.actor }} has been published to [preview environment](http://mattermost-docs-preview-pulls.s3-website-us-east-1.amazonaws.com/${{ steps.pr.outputs.id }}) for Git SHA ${{ github.event.workflow_run.head_sha }} |
101 |
| -
|
102 |
| - - name: The job has failed |
103 |
| - if: ${{ failure() && steps.label-checker.outputs.result == 'true' }} |
104 |
| - uses: peter-evans/create-or-update-comment@7dfe4b0aa0c4bbd06d172692ff8a9e18381d6979 # v3.0.1 |
105 |
| - with: |
106 |
| - token: ${{ secrets.GITHUB_TOKEN }} |
107 |
| - issue-number: ${{ steps.pr.outputs.id }} |
108 |
| - body: Preview environment failed. |
| 18 | + uses: ./.github/workflows/preview-env-template.yml |
| 19 | + secrets: inherit |
| 20 | + with: |
| 21 | + PR_NUMBER: ${{ inputs.PR_NUMBER }} |
| 22 | + TRIGGERING_ACTOR: ${{ inputs.TRIGGERING_ACTOR }} |
| 23 | + COMMIT_SHA: ${{ inputs.COMMIT_SHA }} |
0 commit comments