From a03ed6b6125921ff7f66ac6431782039d604cba4 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Fri, 26 Feb 2021 15:40:06 +0100 Subject: [PATCH] add CI --- .github/workflows/markdown-lint.yml | 26 +++++ .github/workflows/pr-check_redirects.yml | 55 ++++++++++ .github/workflows/pr-lint.yml | 44 ++++++++ .github/workflows/pr-test.yml | 129 +++++++++++++++++++++++ 4 files changed, 254 insertions(+) create mode 100644 .github/workflows/markdown-lint.yml create mode 100644 .github/workflows/pr-check_redirects.yml create mode 100644 .github/workflows/pr-lint.yml create mode 100644 .github/workflows/pr-test.yml diff --git a/.github/workflows/markdown-lint.yml b/.github/workflows/markdown-lint.yml new file mode 100644 index 00000000000000..7a6fde4818309a --- /dev/null +++ b/.github/workflows/markdown-lint.yml @@ -0,0 +1,26 @@ +name: Markdown lint (project files) + +on: + pull_request: + branches: + - main + paths: + - '*.md' + - .github/workflows/markdown-lint.yml + + +jobs: + docs: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup Node.js environment + uses: actions/setup-node@v2 + with: + node-version: "12" + + - name: Lint markdown files + run: | + npx markdownlint-cli '*.md' -i LICENSE.md -i CODE_OF_CONDUCT.md diff --git a/.github/workflows/pr-check_redirects.yml b/.github/workflows/pr-check_redirects.yml new file mode 100644 index 00000000000000..2967d0574fe2bb --- /dev/null +++ b/.github/workflows/pr-check_redirects.yml @@ -0,0 +1,55 @@ +name: Check Redirects + +on: + pull_request: + branches: + - main + paths: + - files/**/_redirects.txt + - .github/workflows/pr-check_redirects.yml + +jobs: + check_redirects: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - uses: actions/checkout@v2 + with: + repository: mdn/content + path: mdn/content + # Yes, this means fetch EVERY COMMIT EVER. + # It's probably not sustainable in the far future (e.g. past 2021) + # but for now it's good enough. We'll need all the history + # so we can figure out each document's last-modified date. + fetch-depth: 0 + + - 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 + run: | + cd $GITHUB_WORKSPACE/mdn/content/ + yarn --frozen-lockfile + + - name: Check redirects file(s) + run: | + export CONTENT_ROOT=$GITHUB_WORKSPACE/mdn/content/files + export CONTENT_TRANSLATED_ROOT=$GITHUB_WORKSPACE/files + + cd $GITHUB_WORKSPACE/mdn/content/ + yarn content validate-redirects --strict diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml new file mode 100644 index 00000000000000..5330e9861935a4 --- /dev/null +++ b/.github/workflows/pr-lint.yml @@ -0,0 +1,44 @@ +# Checks the PR itself for hygiene things. + +name: PR Lint + +on: + pull_request: + # Necessary to re-run if someone edits the PR without a new pushed commit. + types: [opened, edited, synchronize, reopened] + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + path: mdn/translated-content + + - uses: actions/checkout@v2 + with: + repository: mdn/content + path: mdn/content + # Yes, this means fetch EVERY COMMIT EVER. + # It's probably not sustainable in the far future (e.g. past 2021) + # but for now it's good enough. We'll need all the history + # so we can figure out each document's last-modified date. + fetch-depth: 0 + + - name: Setup Node.js environment + uses: actions/setup-node@v2.1.4 + with: + node-version: "12" + + - name: Install all yarn packages + run: | + cd $GITHUB_WORKSPACE/mdn/content/ + cd pr-lint + yarn --frozen-lockfile + + - name: Run checks + run: | + cd $GITHUB_WORKSPACE/mdn/content/ + cd pr-lint + yarn run check diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml new file mode 100644 index 00000000000000..0f17a767c83fd4 --- /dev/null +++ b/.github/workflows/pr-test.yml @@ -0,0 +1,129 @@ +# 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 + # Yes, this means fetch EVERY COMMIT EVER. + # It's probably not sustainable in the far future (e.g. past 2021) + # but for now it's good enough. We'll need all the history + # so we can figure out each document's last-modified date. + fetch-depth: 0 + + - name: Setup Node.js environment + uses: actions/setup-node@v2.1.4 + with: + node-version: "12" + + - name: Cache node_modules + uses: actions/cache@v2.1.4 + id: cached-node_modules + with: + path: | + {{ github.workspace }}/mdn/content/node_modules + key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }} + + - name: Install all yarn packages + if: steps.cached-node_modules.outputs.cache-hit != 'true' + run: | + cd $GITHUB_WORKSPACE/mdn/content/ + 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 }} + run: | + echo ${{ env.GIT_DIFF_CONTENT }} + export CONTENT_ROOT=$GITHUB_WORKSPACE/mdn/content/files + export CONTENT_TRANSLATED_ROOT=$GITHUB_WORKSPACE/files + + # 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 + #