aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/pr-test.yml
blob: be61826133fa69bdb7fec4a563cdeaea407ce182 (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Note that this workflow uses `get-diff-action` which is important.
# It gives us an environment variable called `GIT_DIFF` which is a string
# that is a list of file paths.
# If you want to do what this workflow does on your laptop you can simulate
# it like this:
#
#    export GIT_DIFF=`git diff --name-only main... | grep 'files/' | grep '\.html$'`
#    node content build --no-progressbar --files="${GIT_DIFF}"
#
# That way, you can behave on your laptop like, this action behaves here.

name: PR Test

on:
  pull_request:
    branches:
      - main

jobs:
  tests:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - uses: actions/checkout@v2
        with:
          repository: mdn/content
          path: mdn/content

      - name: Setup Node.js environment
        uses: actions/setup-node@v2.1.4
        with:
          node-version: "12"

      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - uses: actions/cache@v2.1.4
        id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      - name: Install all yarn packages
        working-directory: ${{ github.workspace }}/mdn/content
        run: |
          yarn --frozen-lockfile

      - uses: technote-space/get-diff-action@v4.0.5
        id: git_diff_content
        with:
          PATTERNS: files/**/*.html
          SET_ENV_NAME: GIT_DIFF_CONTENT

      - name: Build changed content
        if: ${{ env.GIT_DIFF_CONTENT }}
        env:
          CONTENT_ROOT: ${{ github.workspace }}/mdn/content/files
          CONTENT_TRANSLATED_ROOT: ${{ github.workspace }}/files
        working-directory: ${{ github.workspace }}/mdn/content
        run: |
          echo ${{ env.GIT_DIFF_CONTENT }}

          # Some day, when our number of flaws have reached 0 we'll change
          # this to "*:error" which means the slightest flaw in the build
          # will break the build.
          # See https://github.com/mdn/yari/issues/715
          export BUILD_FLAW_LEVELS="*:ignore"

          # Note, it might be interesting to explore building *some*
          # pages in a PR build if the diff doesn't have any index.html
          # files changed.
          # Instead of building the git diff, you build some known typical
          # folders that you know don't take too long and do cover a lot
          # of interesting macros etc.
          # This way, when an edit to the source code comes in, perhaps the
          # functional tests have a gap in them but actually building
          # real content exposes it.

          # Setting this to an empty string effectively means that the
          # <iframe> src will end up being the relative URL of the current
          # document as a base.
          # I.e. like this, if the current document is '/en-US/docs/Foo':
          #  <iframe src="/en-US/docs/Foo/_samples_/index.html">
          # ...for example.
          # Yes, it's potentially "insecure" because the iframe will execute
          # whatever code is inserted into the code example. But since the
          # whole (possible) domain for PR builds will never be somewhere
          # where there are interesting cookies, it's a safe choice.
          export BUILD_LIVE_SAMPLES_BASE_URL=

          # In these builds we never care for or need the ability to sign in.
          # This environment variable will disable that functionality entirely.
          export REACT_APP_DISABLE_AUTH=true

          # If we don't do this the built files will end up in
          # `node_modules/@mdn/yari/client/build/` and we don't want that
          # to get pushed into the cache.
          export BUILD_OUT_ROOT=/tmp/

          export BUILD_NO_PROGRESSBAR=true
          # The reason this script isn't in `package.json` is because
          # you don't need that script as a writer. It's only used in CI
          # and it can't use the default CONTENT_ROOT that gets set in
          # package.json.

          yarn build ${{ env.GIT_DIFF_CONTENT }}

      - uses: technote-space/get-diff-action@v4.0.5
        with:
          PATTERNS: files/**/*.+(png|jpeg|jpg|gif|svg|webp)
          ABSOLUTE: true
          SET_ENV_NAME: GIT_DIFF_FILES

      - name: Check changed files
        if: ${{ env.GIT_DIFF_FILES }}
        env:
          CONTENT_ROOT: ${{ github.workspace }}/mdn/content/files
          CONTENT_TRANSLATED_ROOT: ${{ github.workspace }}/files
        working-directory: ${{ github.workspace }}/mdn/content
        run: |
          echo ${{ env.GIT_DIFF_FILES }}

          yarn filecheck ${{ env.GIT_DIFF_FILES }}