Skip to content

Commit 233c99f

Browse files
authored
Changed ci-cd (#6)
* test: Refactored CICD
1 parent 434c1ad commit 233c99f

27 files changed

+3263
-5646
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "Bundle GitHub Page"
2+
description: "This action bundles the current gh-page branch with the out folder"
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: ➕ Create public dir
7+
run: mkdir public
8+
shell: bash
9+
- name: 📥 Get gh-pages tar
10+
run: wget https://github.com/dbsystel/cicd-playground/tarball/gh-pages
11+
shell: bash
12+
- name: 📦 Unpack Tar
13+
run: tar -zxvf gh-pages -C public --strip-components 1
14+
shell: bash
15+
- name: ↔ Extract branch name
16+
shell: bash
17+
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
18+
id: extract_branch
19+
- name: 📁 Move ./out folder to public for preview
20+
if: ${{ !contains( github.ref, 'main') }}
21+
run: mv ./out ./public/${{ steps.extract_branch.outputs.branch }}
22+
shell: bash
23+
- name: 📁 Move ./out folder to public for main
24+
if: ${{ contains( github.ref, 'main') }}
25+
run: mv ./out ./public
26+
shell: bash

.github/actions/npm-cache/action.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: 'NPM Cache Action'
2+
description: 'Initialize NPM Cache'
3+
inputs:
4+
nodeModulesPath:
5+
description: 'Path for node_modules'
6+
required: false
7+
default: './node_modules'
8+
packageLockPath:
9+
description: 'Path for package-lock.json'
10+
required: false
11+
default: './package-lock.json'
12+
runs:
13+
using: "composite"
14+
steps:
15+
- uses: actions/cache@v3
16+
id: 'npm-cache' # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
17+
with:
18+
path: ${{ inputs.nodeModulesPath }}
19+
key: ${{ runner.os }}-node-${{ hashFiles(inputs.packageLockPath) }}
20+
restore-keys: |
21+
${{ runner.os }}-node-
22+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Init Playground Workflow
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
init:
8+
name: Init Playground
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: 🛑 Cancel Previous Runs
12+
uses: styfle/[email protected]
13+
14+
- name: ⬇️ Checkout repo
15+
uses: actions/checkout@v3
16+
17+
- name: 🔄 Init Cache Playground
18+
uses: ./.github/actions/npm-cache
19+
with:
20+
nodeModulesPath: "./playground/pg-simple/node_modules"
21+
packageLockPath: "./playground/pg-simple/package-lock.json"
22+
23+
- name: 📥 Download deps
24+
if: steps.npm-cache.outputs.cache-hit != 'true'
25+
uses: bahmutov/npm-install@v1
26+
with:
27+
working-directory: playground/pg-simple

.github/workflows/00-init.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Init Workflow
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
init:
8+
name: Init
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: 🛑 Cancel Previous Runs
12+
uses: styfle/[email protected]
13+
14+
- name: ⬇️ Checkout repo
15+
uses: actions/checkout@v3
16+
17+
- name: 🔄 Init Cache Default
18+
uses: ./.github/actions/npm-cache
19+
20+
- name: 📥 Download deps default-npm-cache
21+
if: steps.npm-cache.outputs.cache-hit != 'true'
22+
uses: bahmutov/npm-install@v1
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Build Playground
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
build:
8+
name: Build Playground
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: ⬇️ Checkout repo
12+
uses: actions/checkout@v3
13+
14+
- name: 🔄 Init Cache Playground
15+
uses: ./.github/actions/npm-cache
16+
with:
17+
nodeModulesPath: './playground/pg-simple/node_modules'
18+
packageLockPath: './playground/pg-simple/package-lock.json'
19+
20+
- name: 🍼 Build playground
21+
run: cd playground/pg-simple && npm run build
22+
23+

.github/workflows/01-cypress.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Run Cypress on repo
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
cypress:
8+
runs-on: ubuntu-latest
9+
timeout-minutes: 10
10+
steps:
11+
- name: ⬇️ Checkout repo
12+
uses: actions/checkout@v3
13+
14+
- name: 🔄 Init Cache
15+
uses: ./.github/actions/npm-cache
16+
17+
- name: 🍼 Create pages build
18+
run: npm run deploy:pages
19+
20+
- name: 🧪 Cypress run
21+
# Install NPM dependencies and run all Cypress tests
22+
uses: cypress-io/github-action@v4
23+
with:
24+
start: npm run serve
25+
wait-on: "http://localhost:8080"
26+
wait-on-timeout: 120
27+
config: pageLoadTimeout=100000,baseUrl=http://localhost:8080
28+
29+
- name: 🛗 Upload Artifacts
30+
uses: actions/upload-artifact@v2
31+
# after the test run completes
32+
# store videos and any screenshots
33+
# NOTE: screenshots will be generated only if an E2E test failed
34+
# thus we store screenshots only on failures
35+
if: failure()
36+
with:
37+
name: cypress-screenshots
38+
path: e2e/cypress/screenshots
39+
- uses: actions/upload-artifact@v2
40+
# Test run video was always captured, so this action uses "always()" condition
41+
if: always()
42+
with:
43+
name: cypress-videos
44+
path: e2e/cypress/videos
45+

.github/workflows/01-npm-test.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Test NPM Repo
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
test:
8+
name: Test
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: ⬇️ Checkout repo
12+
uses: actions/checkout@v3
13+
14+
- name: 🔄 Init Cache
15+
uses: ./.github/actions/npm-cache
16+
17+
- name: ⚡ Run test
18+
run: npm test
19+
20+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Deploy to gh-pages
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
deploy:
8+
name: Deploy
9+
runs-on: ubuntu-latest
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
steps:
13+
- name: ⬇️ Checkout repo
14+
uses: actions/checkout@v3
15+
16+
- name: 🔄 Init Cache
17+
uses: ./.github/actions/npm-cache
18+
19+
- name: 🍼 Create pages build
20+
run: npm run deploy:pages
21+
22+
- name: ➕ Bundle current gh-pages
23+
uses: ./.github/actions/bundle-gh-page
24+
25+
- name: 🥅 Deploy to GH-Pages
26+
uses: peaceiris/actions-gh-pages@v3
27+
with:
28+
github_token: ${{ secrets.GITHUB_TOKEN }}
29+
publish_dir: ./public
30+
31+

.github/workflows/02-npm-publish.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Publish NPM Repo
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
publish:
8+
name: Publish
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: ⬇️ Checkout repo
12+
uses: actions/checkout@v3
13+
14+
- name: 🔄 Init Cache
15+
uses: ./.github/actions/npm-cache
16+
17+
- name: 📰 Publish to NPM (dry run)
18+
run: npm run publish:abcd

.github/workflows/cleanup.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Cleans all preview pages for gh-pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop
8+
9+
jobs:
10+
clean:
11+
name: Clean
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: 📥 Get gh-pages tar
15+
run: curl -LkSs https://github.com/dbsystel/cicd-playground/tarball/gh-pages -o public.tar.gz
16+
shell: bash
17+
- name: ➕ Create public dir
18+
run: mkdir public
19+
shell: bash
20+
- name: 📦 Unpack Tar
21+
run: tar -xf public.tar.gz -C public --strip-components 1
22+
shell: bash
23+
- name: 🗑️ Clean all preview pages
24+
shell: bash
25+
# TODO: Add script in JS to fetch branches and remove them from public folder
26+
run: curl https://api.github.com/repos/dbsystel/cicd-playground/branches
27+
# TODO: Redeploy public folder to gh-pages
28+

0 commit comments

Comments
 (0)