File: docs-preview.yml

package info (click to toggle)
python-awkward 2.8.10-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 25,144 kB
  • sloc: python: 182,845; cpp: 33,828; sh: 432; makefile: 21; javascript: 8
file content (91 lines) | stat: -rw-r--r-- 3,747 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: Docs Preview
on:
  workflow_run:
    workflows: [Docs]
    types:
      - completed

jobs:
  branch-preview:
    runs-on: ubuntu-24.04
    name: Deploy Branch Preview
    if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }}
    permissions:
      id-token: write
      contents: read
      pull-requests: write
    env:
      S3_BUCKET: "preview.awkward-array.org"
      DEPLOY_URL: "http://preview.awkward-array.org.s3-website.us-east-1.amazonaws.com"
    environment:
      name: docs
      url: "${{ env.DEPLOY_URL }}/PR${{ steps.pr_number.outputs.pr_number }}"
    steps:
    - name: Configure AWS credentials
      uses: aws-actions/configure-aws-credentials@v5
      with:
        aws-region: eu-west-2
        role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_DEPLOY_ROLE }}
    - name: Download rendered docs
      uses: actions/github-script@v8
      with:
        script: |
          let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
              owner: context.repo.owner,
              repo: context.repo.repo,
              run_id: context.payload.workflow_run.id,
          });
          let docsArtifact = allArtifacts.data.artifacts.filter((artifact) => {
            return artifact.name == "docs"
          })[0];
          let PRNumberArtifact = allArtifacts.data.artifacts.filter((artifact) => {
            return artifact.name == "pr_number"
          })[0];
          let downloadDocs = await github.rest.actions.downloadArtifact({
              owner: context.repo.owner,
              repo: context.repo.repo,
              artifact_id: docsArtifact.id,
              archive_format: 'zip',
          });
          let downloadPRNumber = await github.rest.actions.downloadArtifact({
              owner: context.repo.owner,
              repo: context.repo.repo,
              artifact_id: PRNumberArtifact.id,
              archive_format: 'zip',
          });
          const fs = require('fs');
          const path = require('path');
          const temp = '${{ runner.temp }}/artifacts';
          if (!fs.existsSync(temp)){
            fs.mkdirSync(temp);
          }
          fs.writeFileSync(path.join(temp, 'docs.zip'), Buffer.from(downloadDocs.data));
          fs.writeFileSync(path.join(temp, 'pr_number.zip'), Buffer.from(downloadPRNumber.data));
    - name: Unzip artifacts
      run: |
        unzip "${{ runner.temp }}/artifacts/docs.zip" -d "${{ runner.temp }}/artifacts"
        unzip "${{ runner.temp }}/artifacts/pr_number.zip" -d "${{ runner.temp }}/artifacts"
    - name: Read PR number
      id: pr_number
      run: |
        echo "pr_number=$(cat ${{ runner.temp }}/artifacts/pr_number.txt)" >> $GITHUB_OUTPUT
        rm "${{ runner.temp }}/artifacts/pr_number.txt"
        rm "${{ runner.temp }}/artifacts/docs.zip"
        rm "${{ runner.temp }}/artifacts/pr_number.zip"
    - name: Sync artifacts
      run: |
        aws s3 sync ${{ runner.temp }}/artifacts/ "s3://${S3_BUCKET}/PR${{ steps.pr_number.outputs.pr_number }}"
    - name: Try to find previous bot comment
      uses: peter-evans/find-comment@v4
      id: fc
      with:
        issue-number: ${{ steps.pr_number.outputs.pr_number }}
        comment-author: 'github-actions[bot]'
        body-includes: The documentation preview is ready to be viewed
    - name: Create comment with preview link
      if: steps.fc.outputs.comment-id == ''
      uses: peter-evans/create-or-update-comment@v5
      with:
        issue-number: ${{ steps.pr_number.outputs.pr_number }}
        body: |
          The documentation preview is ready to be viewed at <${{ env.DEPLOY_URL }}/PR${{ steps.pr_number.outputs.pr_number }}>