Skip to content

Commit

Permalink
fix: github acitons not working with new yarn v4
Browse files Browse the repository at this point in the history
  • Loading branch information
compojoom committed Dec 18, 2024
1 parent 9d96ed1 commit 9b1c564
Show file tree
Hide file tree
Showing 22 changed files with 258 additions and 2,127 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description: 'Build the app'
inputs:
secrets:
required: true
description: 'GitHub secrets as JSON'

prod: # id of input
description: 'Production build flag'
Expand All @@ -18,6 +19,12 @@ runs:
using: 'composite'

steps:
- name: Restore Next.js Build Cache & Cypress cache
id: restore-nc
uses: ./.github/actions/cache-deps
with:
mode: restore-nc

- name: Set environment variables
shell: bash
run: |
Expand Down Expand Up @@ -60,3 +67,10 @@ runs:
NEXT_PUBLIC_FIREBASE_VAPID_KEY_STAGING: ${{ fromJSON(inputs.secrets).NEXT_PUBLIC_FIREBASE_VAPID_KEY_STAGING }}
NEXT_PUBLIC_SPINDL_SDK_KEY: ${{ fromJSON(inputs.secrets).NEXT_PUBLIC_SPINDL_SDK_KEY }}
NEXT_PUBLIC_ECOSYSTEM_ID_ADDRESS: ${{ fromJSON(inputs.secrets).NEXT_PUBLIC_ECOSYSTEM_ID_ADDRESS }}

- name: Save Next.js Build Cache & Cypress cache
if: steps.restore-nc.outputs.cache-hit-nc != 'true'
uses: ./.github/actions/cache-deps
with:
mode: save-nc
key: ${{ steps.restore-nc.outputs.computed-cache-key-nc }}
85 changes: 85 additions & 0 deletions .github/actions/cache-deps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: "Cache Yarn Dependencies"
description: "Restore or save yarn dependencies"
inputs:
mode:
description: "restore-yarn | save-yarn | restore-nc | safe-nc"
required: true
key:
description: "The cache key to use to safe. Attention! Make sure to use the correct computed cache key depending on the mode"
required: false

outputs:
cache-hit-yarn:
value: ${{ steps.restore.outputs.cache-hit }}
description: "Whether the cache was hit or not"
computed-cache-key-yarn:
value: ${{ steps.restore.outputs.cache-primary-key }}
description: "The computed cache key for yarn"
cache-hit-nc:
value: ${{ steps.restore-nc.outputs.cache-hit }}
description: "Whether the cache was hit or not"
computed-cache-key-nc:
value: ${{ steps.restore-nc.outputs.cache-primary-key }}
description: "The computed cache key for nextjs/cypress"

runs:
using: "composite"
steps:
- name: Restore Yarn Cache
if: ${{ inputs.mode == 'restore-yarn' }}
id: restore
uses: actions/cache/restore@v4
with:
path: |
**/node_modules
/home/runner/.cache/Cypress
${{ github.workspace }}/.yarn/install-state.gz
${{ github.workspace }}/src/types
key: ${{ runner.os }}-web-core-modules-${{ hashFiles('**/package.json','**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-web-core-modules-
- name: Set composite outputs yarn
if: ${{ inputs.mode == 'restore-yarn' }}
shell: bash
run: |
echo "cache-hit-yarn=${{ steps.restore.outputs.cache-hit }}" >> $GITHUB_OUTPUT
echo "computed-cache-key-yarn=${{ steps.restore.outputs.cache-primary-key }}" >> $GITHUB_OUTPUT
- name: Save Yarn Cache
if: ${{ inputs.mode == 'save-yarn' }}
uses: actions/cache/save@v4
with:
path: |
**/node_modules
/home/runner/.cache/Cypress
${{ github.workspace }}/.yarn/install-state.gz
${{ github.workspace }}/src/types
key: ${{inputs.key}}

- name: Restore Next.js
if: ${{ inputs.mode == 'restore-nc' }}
id: restore-nc
uses: actions/cache/restore@v4
with:
path: |
${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-nextjs-cypress-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/yarn.lock') }}-
- name: Set composite outputs nc
if: ${{ inputs.mode == 'restore-nc' }}
shell: bash
run: |
echo "cache-hit-nc=${{ steps.restore-nc.outputs.cache-hit }}" >> $GITHUB_OUTPUT
echo "computed-cache-key-nc=${{ steps.restore-nc.outputs.cache-primary-key }}" >> $GITHUB_OUTPUT
- name: Save Nextj.js
if: ${{ inputs.mode == 'save-nc' }}
uses: actions/cache/save@v4
with:
path: |
${{ github.workspace }}/.next/cache
key: ${{inputs.key}}
8 changes: 8 additions & 0 deletions .github/actions/corepack/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: "Enable corepack"

runs:
using: "composite"
steps:
- name: "Enable Corepack"
shell: bash
run: corepack enable
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,19 @@ inputs:
runs:
using: 'composite'
steps:
- uses: ./.github/workflows/yarn
- uses: ./.github/actions/yarn

- name: Install Latest stable Chrome Version
shell: bash
run: |
curl -O 'https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb'
sudo apt-get install ./google-chrome-stable_current_amd64.deb
- name: Install Cypress 13.15.2
shell: bash
run: yarn add -D [email protected]

- uses: ./.github/workflows/build
- uses: ./.github/actions/build
with:
secrets: ${{ inputs.secrets }}
e2e_mnemonic: ${{ fromJSON(inputs.secrets).NEXT_PUBLIC_CYPRESS_MNEMONIC }}

- name: Serve
shell: bash
run: yarn serve &

- uses: cypress-io/github-action@v6
with:
spec: ${{ inputs.spec }}
Expand All @@ -60,6 +52,8 @@ runs:
record: true
tag: ${{ inputs.tag }}
config: baseUrl=http://localhost:8080
install: false
start: yarn serve
env:
CYPRESS_RECORD_KEY: ${{ inputs.record_key || fromJSON(inputs.secrets).CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ fromJSON(inputs.secrets).GITHUB_TOKEN }}
Expand Down
36 changes: 36 additions & 0 deletions .github/actions/yarn/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 'Yarn'

description: 'Install the dependencies'

runs:
using: 'composite'
steps:
# We require yarn v4 and installing through corepack is the easiest way to get it
- uses: actions/checkout@v4

- uses: ./.github/actions/corepack

- name: Restore Yarn Cache & Types
id: restore-yarn-types
uses: ./.github/actions/cache-deps
with:
mode: restore-yarn

- name: Echo cache hit
shell: bash
run: |
echo "Yarn cache hit: ${{ steps.restore-yarn-types.outputs.cache-hit-yarn }}"
- name: Yarn install & after-install generate types
if: steps.restore-yarn-types.outputs.cache-hit-yarn != 'true'
shell: bash
run: |
yarn install --immutable
yarn after-install
- name: Save Yarn Cache & Types
if: steps.restore-yarn-types.outputs.cache-hit-yarn != 'true'
uses: ./.github/actions/cache-deps
with:
mode: save-yarn
key: ${{ steps.restore-yarn-types.outputs.computed-cache-key-yarn }}
6 changes: 3 additions & 3 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ jobs:

- uses: actions/checkout@v4

- uses: ./.github/workflows/yarn
- uses: ./.github/actions/yarn

- uses: ./.github/workflows/build
- uses: ./.github/actions/build
with:
secrets: ${{ toJSON(secrets) }}
if: startsWith(github.ref, 'refs/heads/main')
# if: startsWith(github.ref, 'refs/heads/main')

#- uses: ./.github/workflows/build-storybook

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: ./.github/workflows/yarn
- uses: ./.github/actions/yarn

- uses: ./.github/workflows/build
- uses: ./.github/actions/build
with:
secrets: ${{ toJSON(secrets) }}
prod: ${{ true }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-full-ondemand.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: ./.github/workflows/cypress
- uses: ./.github/actions/cypress
with:
secrets: ${{ toJSON(secrets) }}
spec: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-hp-ondemand.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: ./.github/workflows/cypress
- uses: ./.github/actions/cypress
with:
secrets: ${{ toJSON(secrets) }}
spec: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-ondemand.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: ./.github/workflows/cypress
- uses: ./.github/actions/cypress
with:
secrets: ${{ toJSON(secrets) }}
spec: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-prod-ondemand.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: ./.github/workflows/cypress
- uses: ./.github/actions/cypress
with:
secrets: ${{ toJSON(secrets) }}
spec: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-safe-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: ./.github/workflows/cypress
- uses: ./.github/actions/cypress
with:
secrets: ${{ toJSON(secrets) }}
spec: cypress/e2e/safe-apps/*.cy.js
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: ./.github/workflows/cypress
- uses: ./.github/actions/cypress
with:
secrets: ${{ toJSON(secrets) }}
spec: cypress/e2e/smoke/*.cy.js
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: ./.github/workflows/yarn
- uses: ./.github/actions/yarn

- uses: CatChen/[email protected]
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nextjs-bundle-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
- uses: actions/checkout@v4

- name: Install dependencies
uses: ./.github/workflows/yarn
uses: ./.github/actions/yarn

- name: Build next.js app
uses: ./.github/workflows/build
uses: ./.github/actions/build
with:
secrets: ${{ toJSON(secrets) }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: ./.github/workflows/yarn
- uses: ./.github/actions/yarn

- name: Annotations and coverage report
uses: ArtiomTr/[email protected]
Expand Down
24 changes: 0 additions & 24 deletions .github/workflows/yarn/action.yml

This file was deleted.

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ yalc.lock
/public/*.js.LICENSE.txt
certificates
*storybook.log
/.yarn

# Yarn v4
.yarn/*
2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
compressionLevel: mixed

enableGlobalCache: false
enableGlobalCache: true

nodeLinker: node-modules
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"cypress:canary": "cross-env TZ=UTC cypress open --e2e -b chrome:canary",
"cypress:run": "cypress run",
"cypress:ci": "yarn cypress:run --config baseUrl=http://localhost:8080 --spec cypress/e2e/smoke/*.cy.js",
"serve": "npx -y serve out -p ${REVERSE_PROXY_UI_PORT:=8080}",
"serve": "sh -c 'npx -y serve out -p ${REVERSE_PROXY_UI_PORT:=8080}'",
"static-serve": "yarn build && yarn serve",
"prepare": "husky",
"storybook": "storybook dev -p 6006",
Expand Down
Loading

0 comments on commit 9b1c564

Please sign in to comment.