Skip to content

Commit

Permalink
chore(CI): run postbuild on main
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed May 31, 2023
1 parent f678366 commit 8d585b6
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 15 deletions.
26 changes: 19 additions & 7 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ env:
ALGOLIA_SEARCH_KEY: ${{ secrets.ALGOLIA_SEARCH_KEY }}
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
CYPRESS_CACHE_FOLDER: ~/.cache/Cypress
RUN_POST_BUILD: ${{ startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/heads/v') }}

jobs:
portal-build:
Expand All @@ -38,10 +39,22 @@ jobs:

steps:
- name: Git checkout
if: ${{ !env.RUN_POST_BUILD }}
uses: actions/checkout@v3
with:
persist-credentials: false

- name: Git checkout (all)
if: ${{ env.RUN_POST_BUILD }}
uses: actions/checkout@v3
with:
persist-credentials: false
fetch-depth: 20 # The "postbuild:ci" method "getCommittedFiles" needs all history

- name: Test
if: ${{ env.RUN_POST_BUILD }}
run: git show --pretty="format:" --name-only HEAD...HEAD~10

- name: Use Node.js
uses: actions/setup-node@v3
with:
Expand All @@ -59,15 +72,14 @@ jobs:
if: steps.modules-cache.outputs.cache-hit != 'true'
run: yarn install --immutable

# We stricly don't need this "prebuild" for running the visual tests.
# Therefore, we only run it on the important pre-release branches, like "main".
# The reason to make a prebuild is;
# - The Portal will then use "/build" (on the CI) – insted the "/src".
# This way, we can catch issues, before its in the "release" branch.
- name: Prebuild Library
if: github.ref == 'refs/heads/main'
if: ${{ env.RUN_POST_BUILD }}
run: yarn workspace @dnb/eufemia prebuild:ci

- name: Postbuild Library
if: ${{ env.RUN_POST_BUILD }}
run: yarn workspace @dnb/eufemia postbuild:ci

- name: Get current date
id: date
run: echo "::set-output name=timestamp::$(date +'%Y-%W')"
Expand All @@ -83,7 +95,7 @@ jobs:
restore-keys: ${{ secrets.CACHE_VERSION }}-${{ runner.os }}-gatsby-

- name: Build portal
run: yarn workspace dnb-design-system-portal build-visual-test
run: yarn workspace dnb-design-system-portal build:visual-test

- name: Store portal artifacts
uses: actions/upload-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/icons-lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
run: yarn workspace @dnb/eufemia test:update

- name: Build portal
run: yarn workspace dnb-design-system-portal build-visual-test
run: yarn workspace dnb-design-system-portal build:visual-test

- name: Store portal artifacts
uses: actions/upload-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion packages/dnb-design-system-portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"build": "gatsby build",
"build:ci": "yarn build:version && gatsby build --prefix-paths",
"build-visual-test": "SKIP_IMAGE_PROCESSING=1 IS_VISUAL_TEST=1 gatsby build --no-uglify",
"build:visual-test": "SKIP_IMAGE_PROCESSING=1 IS_VISUAL_TEST=1 gatsby build --no-uglify",
"build:version": "node ./scripts/version.js --new-version",
"clean": "gatsby clean",
"precommit": "yarn lint-staged",
Expand Down
3 changes: 2 additions & 1 deletion packages/dnb-design-system-portal/src/core/BuildTools.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const fs = require('fs-extra')
function shouldUsePrebuild() {
const rootPath = path.dirname(require.resolve('@dnb/eufemia'))
const buildPath = path.resolve(rootPath, 'build')
const prebuildExists = fs.existsSync(buildPath)
const packageJsonPath = path.resolve(buildPath, 'package.json')
const prebuildExists = fs.existsSync(packageJsonPath)

return Boolean(prebuildExists && process.env.NODE_ENV === 'production')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ This is only meant for "setup testing" purposes! In order to make faster local b
- Inside `gatsby-config.js` rename all sourcing from `/docs` to `/docs_dummy`
Run `yarn workspace dnb-design-system-portal build-visual-test`
Run `yarn workspace dnb-design-system-portal build:visual-test`
## I get Gatsby 404 Not Found on the pages I work on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('babel build', () => {
const buildStages = ['/es', '/esm', '/cjs']

it('imports inside "src" should not contain "/src/"', async () => {
const files = await getCommittedFiles()
const files = await getCommittedFiles(10)

files
.filter((filePath) => {
Expand All @@ -106,7 +106,13 @@ describe('babel build', () => {
const absolutePath = path.resolve(process.cwd(), filePath)
if (fs.existsSync(absolutePath)) {
const content = fs.readFileSync(absolutePath, 'utf-8')
expect(content).not.toMatch(/.*import.*(\/src\/)/)
const regex = /.*import.*(\/src\/)/

if (regex.test(content)) {
console.error('Failed in this file:', absolutePath)
}

expect(content).not.toMatch(regex)
}
})
})
Expand Down
4 changes: 2 additions & 2 deletions packages/dnb-eufemia/scripts/tools/cliTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ function runCommand(command) {
*
* @returns {array} List of files
*/
const getCommittedFiles = async () => {
const getCommittedFiles = async (countCommits = 10) => {
const files = (
await runCommand(
'git config diff.renames 0 && git diff HEAD^ --name-only'
`git config diff.renames 0 && git show --pretty="format:" --name-only HEAD...HEAD~${countCommits}`
)
)
.split('\n')
Expand Down

1 comment on commit 8d585b6

@vercel
Copy link

@vercel vercel bot commented on 8d585b6 May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.