Skip to content

Commit

Permalink
[Actions] ⚡ Optimize workflows (#3480)
Browse files Browse the repository at this point in the history
* 🚚 Moved auth-token, fetch less history

* ♻️ Use composite actions for workflow

* 🐛 Checkout before running composite workflow

* 🚚 Move composite actions to separate dir

* ♻️ Pass token to composite action

* 📝 Better test names

* ⚡ Optimize chromatic workflow

* ⚰️ Removed old and broken redeploy action

* ⚡ Optimized website-build

* ♻️ Use composite actions for prod and dev build

* ⚡ Reduced e2e tests by 40%

* ⚡ Improved sandbox testing

* ⚡ Update search-tests

* 🐛 Disable invalid example-demos

* 🐛 Wait for search completion

* 📝 removed old env input

* 🐛 Moved vars out to input

* 🐛 Don't ignore inputs for if-tests

* 🐛 Check input for truuthynes

* test: Run sharded playwright

* 🐛 Removed sharded workflow

* ⚡ Update re-use of actions

* 🐛 Keep full git-history for chroamtic

* Update .github/workflows/chromatic.yml

Co-authored-by: Lars Eirik Korsgaard Hansen <[email protected]>

* Update .github/workflows/referansesider-spa-deploy.yml

Co-authored-by: Lars Eirik Korsgaard Hansen <[email protected]>

* Update .github/workflows/ci.yml

Co-authored-by: Lars Eirik Korsgaard Hansen <[email protected]>

* Update .github/workflows/ci.yml

Co-authored-by: Lars Eirik Korsgaard Hansen <[email protected]>

* Update .github/workflows/ci.yml

Co-authored-by: Lars Eirik Korsgaard Hansen <[email protected]>

* Update .github/workflows/ci.yml

Co-authored-by: Lars Eirik Korsgaard Hansen <[email protected]>

* Update .github/workflows/ci.yml

Co-authored-by: Lars Eirik Korsgaard Hansen <[email protected]>

* Update .github/workflows/ci.yml

Co-authored-by: Lars Eirik Korsgaard Hansen <[email protected]>

* 📝 Typo

* 📝 Typoo

* ⚡ Use built-in report for playwright

* 🐛 Use html-reporter, not list

---------

Co-authored-by: Lars Eirik Korsgaard Hansen <[email protected]>
  • Loading branch information
KenAJoh and larseirikhansen authored Jan 15, 2025
1 parent fd6e2b4 commit a0ca882
Show file tree
Hide file tree
Showing 37 changed files with 362 additions and 485 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ module.exports = {
},
},
{
files: ["**/examples/__parts*/*.tsx"],
files: [
"**/examples/__parts*/*.tsx",
"**/pages/templates/**/*.tsx",
"**/pages/eksempler/**/*.tsx",
],
plugins: ["aksel-local"],
rules: {
"aksel-local/import-check": ["error"], // Only allow imports from @navikt and react
Expand Down
56 changes: 56 additions & 0 deletions .github/actions/build-website/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: "Build website"
description: "Builds Nextjs-website and published CDN-asssets to GCP if needed"
inputs:
use_cdn_assets:
description: "Use CDN assets, and upload build to GCP"
required: true
npm_auth_token:
description: "NPM Auth Token"
required: true
nais_id_provider:
description: "NAIS_WORKLOAD_IDENTITY_PROVIDER token"
required: true
nais_project_id:
description: "NAIS_MANAGEMENT_PROJECT_ID token"
required: true
sanity_read_token:
description: "Sanity read-only token allowing published and un-published documents"
required: true
sanity_read_no_drafts_token:
description: "Sanity read-only token allowing only published documents"
required: true

runs:
using: "composite"
steps:
- name: Setup project
uses: ./.github/actions/setup
with:
npm_auth_token: ${{ inputs.npm_auth_token }}

- name: Run website tests
run: yarn workspace website test
shell: bash

- name: Make Next.js app use CDN assets
if: ${{ inputs.use_cdn_assets == 'true' }}
run: |
echo "USE_CDN_ASSETS=true" >> aksel.nav.no/website/.env
shell: bash

- name: Build Next.js website
run: yarn build:next
env:
SANITY_READ: ${{ inputs.sanity_read_token }}
SANITY_READ_NO_DRAFTS: ${{ inputs.sanity_read_no_drafts_token }}
shell: bash

- name: Upload static files to Nav CDN
if: ${{ inputs.use_cdn_assets == 'true' }}
uses: nais/deploy/actions/cdn-upload/v2@master
with:
team: designsystem
source: ./aksel.nav.no/website/.next/static
destination: "/website/_next"
project_id: ${{ inputs.nais_project_id }}
identity_provider: ${{ inputs.nais_id_provider }}
26 changes: 26 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Setup Project"
description: "Checks out repo, sets up Node, installs dependencies and runs boot command."
inputs:
npm_auth_token:
description: "NPM Auth Token"
required: true

runs:
using: "composite"
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: yarn
cache-dependency-path: "**/yarn.lock"

- name: Install dependencies
run: yarn
shell: bash
env:
NPM_AUTH_TOKEN: ${{ inputs.npm_auth_token }}

- name: Boot (build packages)
run: yarn boot
shell: bash
44 changes: 11 additions & 33 deletions .github/workflows/aksel-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,20 @@ jobs:
contents: "read"
id-token: "write"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Checkout code
uses: actions/checkout@v4
with:
node-version: lts/*
cache: yarn
- name: set-env for yarn install to @navikt scope
shell: bash
run: echo "NPM_AUTH_TOKEN=${{ secrets.READER_TOKEN }}" >> $GITHUB_ENV
fetch-depth: 1

- name: add tokens to .env
run: |
echo "USE_CDN_ASSETS=true" >> aksel.nav.no/website/.env
- name: Hide page from search engines
run: |
echo "User-agent: *\nDisallow: /" > aksel.nav.no/website/public/robots.txt
- name: Install dependencies
run: yarn

- name: Build application
env:
SANITY_READ: ${{ secrets.SANITY_READ }}
SANITY_READ_NO_DRAFTS: ${{ secrets.SANITY_READ_NO_DRAFTS }}
run: |
yarn boot
yarn workspace aksel.nav.no build:next
- name: Upload static files to Nav CDN
uses: nais/deploy/actions/cdn-upload/v2@master
- name: Setup and build Next.js application
uses: ./.github/actions/build-website
with:
team: designsystem
source: ./aksel.nav.no/website/.next/static
destination: "/website/_next"
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
use_cdn_assets: true
npm_auth_token: ${{ secrets.READER_TOKEN }}
nais_id_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
nais_project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
sanity_read_token: ${{ secrets.SANITY_READ }}
sanity_read_no_drafts_token: ${{ secrets.SANITY_READ_NO_DRAFTS }}

- name: Get complete tag
run: echo "TAG=DEV-$( date +%s )" >> $GITHUB_ENV
Expand Down
63 changes: 16 additions & 47 deletions .github/workflows/aksel-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
- name: Setup project
uses: ./.github/actions/setup
with:
node-version: lts/*
cache: yarn
- name: set-env for yarn install to @navikt scope
shell: bash
run: echo "NPM_AUTH_TOKEN=${{ secrets.READER_TOKEN }}" >> $GITHUB_ENV
npm_auth_token: ${{ secrets.READER_TOKEN }}

- name: Install dependencies
run: yarn

- name: Run docgen
run: |
yarn boot
yarn docgen
- name: Run ts-docgen
run: yarn docgen

- name: Update sanity sync
env:
Expand All @@ -45,43 +37,20 @@ jobs:
contents: "read"
id-token: "write"
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
- name: Checkout code
uses: actions/checkout@v4
with:
node-version: lts/*
cache: yarn
- name: set-env for yarn install to @navikt scope
shell: bash
run: echo "NPM_AUTH_TOKEN=${{ secrets.READER_TOKEN }}" >> $GITHUB_ENV

- name: add tokens to .env
run: |
echo "USE_CDN_ASSETS=true" >> aksel.nav.no/website/.env
- name: Install dependencies
run: yarn

- name: Build packages
run: yarn boot
fetch-depth: 1

- name: Tests
run: yarn workspace website test

- name: Build application
env:
SANITY_READ: ${{ secrets.SANITY_READ }}
SANITY_READ_NO_DRAFTS: ${{ secrets.SANITY_READ_NO_DRAFTS }}
run: yarn workspace aksel.nav.no build:next

- name: Upload static files to Nav CDN
uses: nais/deploy/actions/cdn-upload/v2@master
- name: Setup and build Next.js application
uses: ./.github/actions/build-website
with:
team: designsystem
source: ./aksel.nav.no/website/.next/static
destination: "/website/_next"
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
use_cdn_assets: true
npm_auth_token: ${{ secrets.READER_TOKEN }}
nais_id_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
nais_project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
sanity_read_token: ${{ secrets.SANITY_READ }}
sanity_read_no_drafts_token: ${{ secrets.SANITY_READ_NO_DRAFTS }}

- name: Get complete tag
run: echo "TAG=PROD-$( date +%s )" >> $GITHUB_ENV
Expand Down
42 changes: 0 additions & 42 deletions .github/workflows/aksel-redeploy.yml

This file was deleted.

9 changes: 5 additions & 4 deletions .github/workflows/backup-sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ jobs:
with:
node-version: lts/*
cache: yarn
- name: set-env for yarn install to @navikt scope
shell: bash
run: echo "NPM_AUTH_TOKEN=${{ secrets.READER_TOKEN }}" >> $GITHUB_ENV
cache-dependency-path: "**/yarn.lock"

- name: Install dependencies
run: cd aksel.nav.no/website && yarn
env:
NPM_AUTH_TOKEN: ${{ secrets.READER_TOKEN }}

- name: Export dataset
run: cd aksel.nav.no/website && yarn backup
env:
SANITY_READ: ${{ secrets.SANITY_READ }}
run: cd aksel.nav.no/website && yarn backup

- name: Upload GCP bucket
uses: "google-github-actions/auth@v2"
with:
Expand Down
20 changes: 5 additions & 15 deletions .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,21 @@ concurrency:

jobs:
chromatic:
if: ${{ !contains(github.event.pull_request.labels.*.name, 'ignore-chromatic') }}
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
contents: write
steps:
- uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
- name: Setup project
uses: ./.github/actions/setup
with:
node-version: lts/*
cache: yarn

- name: set-env for yarn install to @navikt scope
shell: bash
run: echo "NPM_AUTH_TOKEN=${{ secrets.READER_TOKEN }}" >> $GITHUB_ENV

- name: Install dependencies
run: yarn

- name: Build packages
run: yarn boot
npm_auth_token: ${{ secrets.READER_TOKEN }}

- name: Chromatic
uses: chromaui/action@latest
Expand Down
Loading

0 comments on commit a0ca882

Please sign in to comment.