Merge pull request #864 from WTW-IM/pre-prod #1348
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
pull_request_target: | |
push: | |
branches: | |
- main | |
jobs: | |
test: | |
name: Test with Node v${{matrix.node}} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node: [lts/*, node] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.PIPELINE_BOT_PAT }} | |
ref: ${{ github.head_ref || github.ref }} | |
repository: ${{ ( | |
github.event_name == 'pull_request_target' && | |
github.event.pull_request.head.repo.full_name | |
) || github.repository }} | |
fetch-depth: 0 | |
- name: Use Node Version | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node }} | |
cache: 'npm' | |
- uses: actions/cache@v3 | |
with: | |
path: '**/node_modules' | |
key: ${{ runner.os }}-${{ hashFiles('package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}- | |
- name: Install Dependencies | |
run: | | |
npm i --prefer-offline --no-audit | |
- name: Run Lint | |
working-directory: packages/es-components | |
if: ${{ github.event_name == 'pull_request_target' }} | |
continue-on-error: true | |
run: | | |
npx eslint \ | |
--output-file eslint_report.json \ | |
--format json \ | |
--no-error-on-unmatched-pattern \ | |
$(git diff ${{ github.base_ref }} --name-only --relative) | |
- name: Annotate JS Linting Results | |
if: ${{ github.event_name == 'pull_request_target' }} | |
uses: ataylorme/eslint-annotate-action@v2 | |
with: | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
report-json: packages/es-components/eslint_report.json | |
- name: Run Tests | |
run: | | |
npm test --workspaces --if-present | |
npm: | |
if: ${{ github.ref == 'refs/heads/main' }} | |
needs: [test] | |
name: Publish NPM Packages | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.PIPELINE_BOT_PAT }} | |
ref: main | |
fetch-depth: 0 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 'lts/*' | |
cache: 'npm' | |
- uses: actions/cache@v3 | |
with: | |
path: '**/node_modules' | |
key: ${{ runner.os }}-${{ hashFiles('package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}- | |
- name: Install Dependencies | |
run: | | |
npm i --prefer-offline --no-audit | |
- name: Set Commitbot Identity | |
run: | | |
git config user.name "ES-Components Lerna Publish Bot" | |
git config user.email "[email protected]" | |
- name: Lerna Publish Latest | |
run: | | |
echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > ~/.npmrc | |
npx lerna publish \ | |
--conventional-commits \ | |
--changelog-preset @aabenoja/conventional-changelog-eslint-lerna \ | |
--conventional-graduate \ | |
--yes | |
npm_prerelease: | |
if: ${{ github.ref == 'refs/heads/main' }} | |
needs: [test, npm] | |
name: Pre-Prod Publish | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.PIPELINE_BOT_PAT }} | |
ref: pre-prod | |
fetch-depth: 0 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 'lts/*' | |
cache: 'npm' | |
- uses: actions/cache@v3 | |
with: | |
path: '**/node_modules' | |
key: ${{ runner.os }}-${{ hashFiles('package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}- | |
- name: Install Dependencies | |
run: | | |
npm i --prefer-offline --no-audit | |
- name: Set Commitbot Identity | |
run: | | |
git config user.name "ES-Components Lerna Publish Bot" | |
git config user.email "[email protected]" | |
- name: Merge main to pre-prod | |
run: | | |
git merge --no-verify -Xtheirs --commit origin/main -m "Build: merging main into pre-prod" | |
# abort if failed merge | |
git merge --abort || true | |
git push origin pre-prod | |
# This is so that we always update the pre-prod dist tag with main when we merge. | |
# (Pre-prod can be ahead of main, but never behind.) | |
- name: Lerna Publish Pre-Prod | |
run: | | |
echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > ~/.npmrc | |
npx lerna publish \ | |
--conventional-commits \ | |
--changelog-preset @aabenoja/conventional-changelog-eslint-lerna \ | |
--conventional-prerelease \ | |
--dist-tag pre-prod \ | |
--preid pre-prod \ | |
--allow-branch pre-prod \ | |
--yes | |
docs: | |
if: ${{ github.ref == 'refs/heads/main' }} | |
needs: npm | |
name: Publish Docs to GH Pages | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.PIPELINE_BOT_PAT }} | |
ref: main | |
fetch-depth: 0 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 'lts/*' | |
cache: 'npm' | |
- uses: actions/cache@v3 | |
with: | |
path: '**/node_modules' | |
key: ${{ runner.os }}-${{ hashFiles('package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}- | |
- name: Install Dependencies | |
run: | | |
npm i --prefer-offline --no-audit | |
- name: Set Commitbot Identity | |
run: | | |
git config user.name "ES-Components Lerna Publish Bot" | |
git config user.email "[email protected]" | |
- name: Rebuild docs | |
working-directory: packages/es-components | |
run: | | |
npm run styleguide-build | |
- name: Configure docs changes | |
run: | | |
git stash | |
git checkout gh-pages | |
git stash show -p | git apply && git stash drop | |
rm -rf build/ | |
mv ./packages/es-components/docs/* . | |
git add index.html full-color-icons.html full-color-icons.js build | |
DIFF_RESULT=$(git diff --staged --quiet --exit-code; echo "$?") | |
HAS_CHANGES=$( | |
if [ $DIFF_RESULT -eq 0 ] | |
then echo "false" | |
else echo "true" | |
fi | |
) | |
echo "Has docs changes? $HAS_CHANGES" | |
echo "HAS_CHANGES=$HAS_CHANGES" >> $GITHUB_ENV | |
- name: Publish docs to github pages | |
if: env.HAS_CHANGES == 'true' | |
run: | | |
git commit -m "Deploy es-component docs to gh-pages" | |
git push origin gh-pages |