diff --git a/.github/actions/npm-cache/action.yml b/.github/actions/npm-cache/action.yml new file mode 100644 index 0000000000..5649ef4126 --- /dev/null +++ b/.github/actions/npm-cache/action.yml @@ -0,0 +1,12 @@ +name: "NPM Cache Action" +description: "Initialize NPM Cache" +runs: + using: "composite" + steps: + - uses: actions/cache@v3 + id: "npm-cache" # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true' + with: + path: "./node_modules" + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- diff --git a/.github/workflows/00-init.yml b/.github/workflows/00-init.yml new file mode 100644 index 0000000000..ef26ec2c84 --- /dev/null +++ b/.github/workflows/00-init.yml @@ -0,0 +1,22 @@ +name: Init Workflow + +on: + workflow_call: + +jobs: + init: + name: Init + runs-on: ubuntu-latest + steps: + - name: 🛑 Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + + - name: ⬇️ Checkout repo + uses: actions/checkout@v3 + + - name: 🔄 Init Cache Default + uses: ./.github/actions/npm-cache + + - name: 📥 Download deps default-npm-cache + if: steps.npm-cache.outputs.cache-hit != 'true' + uses: bahmutov/npm-install@v1 diff --git a/.github/workflows/01-build.yml b/.github/workflows/01-build.yml new file mode 100644 index 0000000000..bf1fa9df02 --- /dev/null +++ b/.github/workflows/01-build.yml @@ -0,0 +1,24 @@ +name: Build Pages + +on: + workflow_call: + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: ⬇️ Checkout repo + uses: actions/checkout@v3 + + - name: 🔄 Init Cache + uses: ./.github/actions/npm-cache + + - name: 🍼 Create pages build + run: npm run build + + - name: ⬆️Upload build + uses: actions/upload-artifact@v3 + with: + name: build + path: public diff --git a/.github/workflows/01-lint.yml b/.github/workflows/01-lint.yml new file mode 100644 index 0000000000..e9a89de2e7 --- /dev/null +++ b/.github/workflows/01-lint.yml @@ -0,0 +1,18 @@ +name: Lint + +on: + workflow_call: + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: ⬇️ Checkout repo + uses: actions/checkout@v3 + + - name: 🔄 Init Cache + uses: ./.github/actions/npm-cache + + - name: ⚡ Run Test + run: npm run lint diff --git a/.github/workflows/01-test.yml b/.github/workflows/01-test.yml new file mode 100644 index 0000000000..6c815a8c2f --- /dev/null +++ b/.github/workflows/01-test.yml @@ -0,0 +1,18 @@ +name: Test + +on: + workflow_call: + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: ⬇️ Checkout repo + uses: actions/checkout@v3 + + - name: 🔄 Init Cache + uses: ./.github/actions/npm-cache + + - name: ⚡ Run Test + run: npm run test diff --git a/.github/workflows/02-deploy-gh-pages.yml b/.github/workflows/02-deploy-gh-pages.yml new file mode 100644 index 0000000000..fa3cca0509 --- /dev/null +++ b/.github/workflows/02-deploy-gh-pages.yml @@ -0,0 +1,29 @@ +name: Deploy to gh-pages + +on: + workflow_call: + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + steps: + - name: ⬇️ Checkout repo + uses: actions/checkout@v3 + + - name: 🔄 Init Cache + uses: ./.github/actions/npm-cache + + - name: ⬇️Download build + uses: actions/download-artifact@v3 + with: + name: build + path: public + + - name: 🥅 Deploy to GH-Pages + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./public diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml new file mode 100644 index 0000000000..dff8e909df --- /dev/null +++ b/.github/workflows/default.yml @@ -0,0 +1,24 @@ +name: Default push workflow + +on: [push] + +jobs: + init: + uses: ./.github/workflows/00-init.yml + + lint: + uses: ./.github/workflows/01-lint.yml + needs: [init] + + test: + uses: ./.github/workflows/01-test.yml + needs: [init] + + build: + uses: ./.github/workflows/01-build.yml + needs: [init] + + deploy: + if: contains( github.ref, 'main') + uses: ./.github/workflows/02-deploy-gh-pages.yml + needs: [lint, test, build] diff --git a/.github/workflows/gh_pages.yml b/.github/workflows/gh_pages.yml deleted file mode 100644 index f4210c0d11..0000000000 --- a/.github/workflows/gh_pages.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: GitHub Pages - -on: - push: - branches: - - main # Set a branch name to trigger deployment - -jobs: - deploy: - runs-on: ubuntu-20.04 - concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - steps: - - uses: actions/checkout@v3 - - name: NPM install - run: npm ci - - name: NPM Build - run: npm run build - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 - if: ${{ github.ref == 'refs/heads/main' }} - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./public