Skip to content

preview-env-fork-setup-update #5452

preview-env-fork-setup-update

preview-env-fork-setup-update #5452

name: preview-env-fork-setup-update
on:
workflow_run:
workflows: ["check-label-preview-env"]
types: [completed]
jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Download PR number artifact
uses: dawidd6/action-download-artifact@0c49384d39ceb023b8040f480a25596fd6cf441b # v2.26.0
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
name: pr.txt
- name: Save PR number
id: pr
run: |
echo "::set-output name=id::$(<pr.txt)"
- name: Check label
uses: actions/github-script@6f00a0b667f9463337970371ccda9072ee86fb27 # v6.4.1
id: label-checker
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
let fs = require('fs');
let issue_number = Number(fs.readFileSync('./pr.txt'));
const query = `query($owner:String!, $name:String!, $pr:Int!) {
repository(owner:$owner, name:$name){
pullRequest(number:$pr) {
labels(first:50) {
nodes{
name
}
}
}
}
}`;
const variables = {
owner: 'mattermost',
name: 'docs',
pr: issue_number
};
const result = await github.graphql(query, variables);
console.log(result.repository.pullRequest.labels.nodes);
const labels = result.repository.pullRequest.labels.nodes;
for (var index = 0; index < labels.length; ++index) {
var label = labels[index];
if(label.name == 'preview-environment') {
return true;
}
}
return false;
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
if: ${{ steps.label-checker.outputs.result == 'true' }}
with:
ref: ${{ github.event.workflow_run.head_sha }}
token: ${{ secrets.GITHUB_TOKEN }}
submodules: true
fetch-depth: 0
- name: Setup Python
if: ${{ steps.label-checker.outputs.result == 'true' }}
uses: actions/setup-python@db9987b4c1f10f0404fa60ee629f675fafbd6763 # v4.6.0
with:
python-version: '3.9'
- name: Install pipenv
if: ${{ steps.label-checker.outputs.result == 'true' }}
run: pip install pipenv
- name: Install dependencies
if: ${{ steps.label-checker.outputs.result == 'true' }}
run: pipenv install --dev
- name: Build
if: ${{ steps.label-checker.outputs.result == 'true' }}
run: make SPHINXOPTS="-j auto -D mm_url_path_prefix=/${{ steps.pr.outputs.id }}" html
- uses: shallwefootball/s3-upload-action@4350529f410221787ccf424e50133cbc1b52704e # v1.3.3
name: Upload Preview Env
if: ${{ steps.label-checker.outputs.result == 'true' }}
with:
aws_key_id: ${{ secrets.AWS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_bucket: ${{ secrets.AWS_BUCKET }}
source_dir: ./build/html
destination_dir: ${{ steps.pr.outputs.id }}
- name: Add comment to PR
uses: peter-evans/create-or-update-comment@7dfe4b0aa0c4bbd06d172692ff8a9e18381d6979 # v3.0.1
if: ${{ success() && steps.label-checker.outputs.result == 'true' }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ steps.pr.outputs.id }}
body: |
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 }}
- name: The job has failed
if: ${{ failure() && steps.label-checker.outputs.result == 'true' }}
uses: peter-evans/create-or-update-comment@7dfe4b0aa0c4bbd06d172692ff8a9e18381d6979 # v3.0.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ steps.pr.outputs.id }}
body: Preview environment failed.