Skip to content

Commit

Permalink
feat: add gh actions
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckySoLucky committed Jun 13, 2024
1 parent b592102 commit 996f6a3
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 297 deletions.
86 changes: 86 additions & 0 deletions .github/pnpm-install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
########################################################################################
# "pnpm install" composite action for pnpm 7/8+ #
#--------------------------------------------------------------------------------------#
# Requirement: @setup/node should be run before #
# #
# Usage in workflows steps: #
# #
# - name: 📥 Monorepo install #
# uses: ./.github/actions/pnpm-install #
# with: #
# enable-corepack: false # (default) #
# cwd: ${{ github.workspace }}/apps/my-app # (default = '.') #
# #
# Reference: #
# - latest: https://gist.github.com/belgattitude/838b2eba30c324f1f0033a797bab2e31 #
# #
# Versions: #
# - 1.1.0 - 15-07-2023 - Add project custom directory support. #
########################################################################################

name: 'PNPM install'
description: 'Run pnpm install with cache enabled'

inputs:
enable-corepack:
description: 'Enable corepack'
required: false
default: 'false'
cwd:
description: "Changes node's process.cwd() if the project is not located on the root. Default to process.cwd()"
required: false
default: '.'

runs:
using: 'composite'

steps:
- name: ⚙️ Enable Corepack
if: ${{ inputs.enable-corepack == 'true' }}
shell: bash
working-directory: ${{ inputs.cwd }}
run: |
corepack enable
echo "corepack enabled"
- uses: pnpm/[email protected]
if: ${{ inputs.enable-corepack == 'false' }}
with:
run_install: false
# If you're not setting the packageManager field in package.json, add the version here
version: 8.6.11

- name: Expose pnpm config(s) through "$GITHUB_OUTPUT"
id: pnpm-config
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Cache rotation keys
id: cache-rotation
shell: bash
run: |
echo "YEAR_MONTH=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-config.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-
# Prevent store to grow over time (not needed with yarn)
# Note: not perfect as it prune too much in monorepos so the idea
# is to use cache-rotation as above. In the future this might work better.
#- name: Prune pnpm store
# shell: bash
# run: pnpm prune store

- name: Install dependencies
shell: bash
working-directory: ${{ inputs.cwd }}
run: pnpm install --frozen-lockfile --prefer-offline
env:
# Other environment variables
HUSKY: '0' # By default do not run HUSKY install
36 changes: 36 additions & 0 deletions .github/workflows/cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
name: Cleanup caches for closed branches

on:
pull_request:
types:
- closed
workflow_dispatch:

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Cleanup
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78 changes: 78 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Website

on:
push:
paths: ['src/**', '.github/workflows/website.yml']

pull_request:
paths: ['src/**', '.github/workflows/website.yml']

env:
NODE_VERSION: '19'
CONTAINER_REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
es-lint:
name: Check linting (es-lint)
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: PNPM Install
uses: ./.github/actions/pnpm-install

- name: Check ESlint
run: pnpm lint

prettier:
name: Check formatting (prettier)
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: PNPM Install
uses: ./.github/actions/pnpm-install

- name: Check Prettier
run: pnpm prettier --check .

sveltecheck:
name: Svelte Check
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: PNPM Install
uses: ./.github/actions/pnpm-install

- name: Make dummy env for types
run: |
echo "ls -a ."
ls -a .
mv .env.example .env
- name: Check Svelte
run: pnpm run check

build:
name: Svelte Build
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: PNPM Install
uses: ./.github/actions/pnpm-install

- name: Make dummy env for types
run: |
echo "ls -a ."
ls -a .
mv .env.example .env
- name: Svelte Build
run: pnpm run build
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@types/relaxed-json": "^1.0.4",
"@types/upng-js": "^2.1.5",
"apng2gif-bin": "^1.7.1",
"canvas": "^2.11.2",
"dotenv": "^16.4.5",
"fs-extra": "^11.2.0",
"lodash": "^4.17.21",
"micromatch": "^4.0.7",
Expand Down
Loading

0 comments on commit 996f6a3

Please sign in to comment.