diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml new file mode 100644 index 0000000..5e47f36 --- /dev/null +++ b/.github/actions/build/action.yml @@ -0,0 +1,21 @@ +name: 'Build' +description: 'Builds project' +runs: + using: 'composite' + steps: + # Based on https://nextjs.org/docs/messages/no-cache#github-actions + - uses: actions/cache@v2 + id: cache-build + with: + path: | + ~/.npm + ${{ github.workspace }}/.next/cache + # Generate a new cache whenever packages or source files change. + key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} + # If source files changed but packages didn't, rebuild from a prior cache. + restore-keys: | + ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- + - name: Build project + if: steps.cache-build.outputs.cache-hit != 'true' + run: npm run build + shell: bash diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 0000000..6f5ed89 --- /dev/null +++ b/.github/actions/setup/action.yml @@ -0,0 +1,14 @@ +name: 'Setup' +description: 'Setup node and dependencies' +runs: + using: 'composite' + steps: + - name: Setup node + id: setup-node + uses: actions/setup-node@v2 + with: + node-version-file: '.node-version' + cache: 'npm' + - name: Install dependencies + run: npm ci + shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e4fc51..ceed0c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,18 +7,29 @@ on: branches: [main] jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/setup + - uses: ./.github/actions/build + test: + name: Test + needs: [build] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/setup + - uses: ./.github/actions/build + - name: Run tests + run: npm run test format: name: Format runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Setup node - uses: actions/setup-node@v2 - with: - node-version-file: '.node-version' - cache: 'npm' - - name: Install dependencies - run: npm ci + - uses: ./.github/actions/setup - name: Run prettier run: npm run format:ci lint: @@ -26,26 +37,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Setup node - uses: actions/setup-node@v2 - with: - node-version-file: '.node-version' - cache: 'npm' - - name: Install dependencies - run: npm ci + - uses: ./.github/actions/setup - name: Run eslint run: npm run lint:ci - build: - name: Build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup node - uses: actions/setup-node@v2 - with: - node-version-file: '.node-version' - cache: 'npm' - - name: Install dependencies - run: npm ci - - name: Build project - run: npm run build --if-present diff --git a/package.json b/package.json index 9cffbdb..e3536cc 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "dev": "next dev", "build": "next build", "start": "next start", + "test": "echo 'No tests configured'", "lint": "next lint", "lint:fix": "next lint --fix", "lint:ci": "npm run lint -- --max-warnings 0",