Skip to content

Commit 55a68c7

Browse files
authored
fix: Migrate fork triggering functionality to Argo Events (mattermost#7144)
* fix: Migrate fork triggering functionality to Argo Events * fix: Fixed proper actor from pull request head
1 parent 08e4c84 commit 55a68c7

File tree

4 files changed

+78
-169
lines changed

4 files changed

+78
-169
lines changed

.github/workflows/check-label.yml

-23
This file was deleted.
+17-102
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,23 @@
11
name: preview-env-fork-setup-update
22

33
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
715

816
jobs:
917
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 }}
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: preview-env-setup-template
2+
3+
on:
4+
workflow_call:
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
15+
16+
jobs:
17+
deploy:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
21+
with:
22+
submodules: true
23+
fetch-depth: 0
24+
25+
- name: Setup Python
26+
uses: actions/setup-python@db9987b4c1f10f0404fa60ee629f675fafbd6763 # v4.6.0
27+
with:
28+
python-version: "3.9"
29+
30+
- name: Install pipenv
31+
run: pip install pipenv
32+
33+
- name: Install dependencies
34+
run: pipenv install --dev
35+
36+
- name: Build
37+
run: make SPHINXOPTS="-j auto -D html_baseurl=http://mattermost-docs-preview-pulls.s3-website-us-east-1.amazonaws.com/${{ inputs.PR_NUMBER }}" html
38+
39+
- uses: shallwefootball/s3-upload-action@4350529f410221787ccf424e50133cbc1b52704e # v1.3.3
40+
name: Upload Preview Env
41+
with:
42+
aws_key_id: ${{ secrets.AWS_KEY_ID }}
43+
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
44+
aws_bucket: ${{ secrets.AWS_BUCKET }}
45+
source_dir: ./build/html
46+
destination_dir: ${{ inputs.PR_NUMBER }}
47+
48+
- name: Add comment to PR
49+
uses: peter-evans/create-or-update-comment@7dfe4b0aa0c4bbd06d172692ff8a9e18381d6979 # v3.0.1
50+
with:
51+
token: ${{ secrets.GITHUB_TOKEN }}
52+
issue-number: ${{ inputs.PR_NUMBER }}
53+
body: |
54+
Newest code from ${{ inputs.TRIGGERING_ACTOR }} has been published to [preview environment](http://mattermost-docs-preview-pulls.s3-website-us-east-1.amazonaws.com/${{ inputs.PR_NUMBER }}) for Git SHA ${{ inputs.COMMIT_SHA }}

.github/workflows/preview-env.yml

+7-44
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,10 @@ on:
66

77
jobs:
88
deploy:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
12-
if: github.event.pull_request.head.repo.full_name == github.repository
13-
with:
14-
submodules: true
15-
fetch-depth: 0
16-
17-
- name: Setup Python
18-
if: github.event.pull_request.head.repo.full_name == github.repository
19-
uses: actions/setup-python@db9987b4c1f10f0404fa60ee629f675fafbd6763 # v4.6.0
20-
with:
21-
python-version: '3.9'
22-
23-
- name: Install pipenv
24-
if: github.event.pull_request.head.repo.full_name == github.repository
25-
run: pip install pipenv
26-
27-
- name: Install dependencies
28-
if: github.event.pull_request.head.repo.full_name == github.repository
29-
run: pipenv install --dev
30-
31-
- name: Build
32-
if: github.event.pull_request.head.repo.full_name == github.repository
33-
run: make SPHINXOPTS="-j auto -D html_baseurl=http://mattermost-docs-preview-pulls.s3-website-us-east-1.amazonaws.com/${{ github.event.number }}" html
34-
35-
- uses: shallwefootball/s3-upload-action@4350529f410221787ccf424e50133cbc1b52704e # v1.3.3
36-
name: Upload Preview Env
37-
if: github.event.pull_request.head.repo.full_name == github.repository
38-
with:
39-
aws_key_id: ${{ secrets.AWS_KEY_ID }}
40-
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
41-
aws_bucket: ${{ secrets.AWS_BUCKET }}
42-
source_dir: ./build/html
43-
destination_dir: ${{ github.event.number }}
44-
45-
- name: Add comment to PR
46-
if: github.event.pull_request.head.repo.full_name == github.repository
47-
uses: peter-evans/create-or-update-comment@7dfe4b0aa0c4bbd06d172692ff8a9e18381d6979 # v3.0.1
48-
with:
49-
token: ${{ secrets.GITHUB_TOKEN }}
50-
issue-number: ${{ github.event.number }}
51-
body: |
52-
Newest code from ${{ github.actor }} has been published to [preview environment](http://mattermost-docs-preview-pulls.s3-website-us-east-1.amazonaws.com/${{ github.event.number }}) for Git SHA ${{ github.event.pull_request.head.sha }}
9+
uses: ./.github/workflows/preview-env-template.yml
10+
if: github.event.pull_request.head.repo.full_name == github.repository
11+
secrets: inherit
12+
with:
13+
PR_NUMBER: ${{ github.event.number }}
14+
TRIGGERING_ACTOR: ${{ github.event.pull_request.head.user.login }}
15+
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}

0 commit comments

Comments
 (0)