Skip to content

Commit 813c39f

Browse files
authored
Test artifacts (#7)
* feat: add upload/download for build artifacts
1 parent 233c99f commit 813c39f

27 files changed

+1617
-975
lines changed

.github/actions/bundle-gh-page/action.yml

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,46 @@ description: "This action bundles the current gh-page branch with the out folder
33
runs:
44
using: "composite"
55
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
156
- name: ↔ Extract branch name
167
shell: bash
178
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
189
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 }}
10+
- name: ➕ Create temp or public dir
11+
run: |
12+
echo "Create dir for branch: ${{ steps.extract_branch.outputs.branch }}"
13+
if echo ${{ steps.extract_branch.outputs.branch }} | grep -c "main"
14+
then
15+
mkdir temp
16+
echo "Created 'temp' dir"
17+
else
18+
mkdir public
19+
echo "Created 'public' dir"
20+
fi
21+
shell: bash
22+
- name: 📥 Get gh-pages tar
23+
run: wget -q https://github.com/dbsystel/cicd-playground/tarball/gh-pages
24+
shell: bash
25+
- name: 📦 Unpack Tar
26+
run: |
27+
if echo ${{ steps.extract_branch.outputs.branch }} | grep -c "main"
28+
then
29+
tar -zxf gh-pages -C temp --strip-components 1
30+
else
31+
tar -zxf gh-pages -C public --strip-components 1
32+
fi
2233
shell: bash
23-
- name: 📁 Move ./out folder to public for main
24-
if: ${{ contains( github.ref, 'main') }}
25-
run: mv ./out ./public
34+
- name: 📁 Move ./out folder to public
35+
run: |
36+
if echo ${{ steps.extract_branch.outputs.branch }} | grep -c "main"
37+
then
38+
mv ./out ./public
39+
if [ -d ./temp/review ]; then
40+
mv ./temp/review ./public
41+
fi
42+
else
43+
if [ ! -d ./public/review ]; then
44+
mkdir ./public/review
45+
fi
46+
mv ./out ./public/review/${{ steps.extract_branch.outputs.branch }}
47+
fi
2648
shell: bash

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
name: 'NPM Cache Action'
2-
description: 'Initialize NPM Cache'
1+
name: "NPM Cache Action"
2+
description: "Initialize NPM Cache"
33
inputs:
44
nodeModulesPath:
5-
description: 'Path for node_modules'
5+
description: "Path for node_modules"
66
required: false
7-
default: './node_modules'
7+
default: "./node_modules"
88
packageLockPath:
9-
description: 'Path for package-lock.json'
9+
description: "Path for package-lock.json"
1010
required: false
11-
default: './package-lock.json'
11+
default: "./package-lock.json"
1212
runs:
1313
using: "composite"
1414
steps:
1515
- uses: actions/cache@v3
16-
id: 'npm-cache' # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
16+
id: "npm-cache" # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
1717
with:
1818
path: ${{ inputs.nodeModulesPath }}
1919
key: ${{ runner.os }}-node-${{ hashFiles(inputs.packageLockPath) }}
2020
restore-keys: |
2121
${{ runner.os }}-node-
22-

.github/workflows/01-build-playground.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ jobs:
1414
- name: 🔄 Init Cache Playground
1515
uses: ./.github/actions/npm-cache
1616
with:
17-
nodeModulesPath: './playground/pg-simple/node_modules'
18-
packageLockPath: './playground/pg-simple/package-lock.json'
17+
nodeModulesPath: "./playground/pg-simple/node_modules"
18+
packageLockPath: "./playground/pg-simple/package-lock.json"
1919

2020
- name: 🍼 Build playground
2121
run: cd playground/pg-simple && npm run build
22-
23-

.github/workflows/01-build.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Build Pages
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
build:
8+
name: Build
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: 🍼 Create pages build
18+
run: npm run deploy:pages
19+
20+
- name: ⬆️Upload build
21+
uses: actions/upload-artifact@v3
22+
with:
23+
name: build
24+
path: out

.github/workflows/01-cypress.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ jobs:
1414
- name: 🔄 Init Cache
1515
uses: ./.github/actions/npm-cache
1616

17-
- name: 🍼 Create pages build
18-
run: npm run deploy:pages
17+
- name: ⬇️Download build
18+
uses: actions/download-artifact@v3
19+
with:
20+
name: build
21+
path: out
22+
23+
- name: Check for out dir
24+
run: ls out
1925

2026
- name: 🧪 Cypress run
2127
# Install NPM dependencies and run all Cypress tests
@@ -42,4 +48,3 @@ jobs:
4248
with:
4349
name: cypress-videos
4450
path: e2e/cypress/videos
45-

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,3 @@ jobs:
1616

1717
- name: ⚡ Run test
1818
run: npm test
19-
20-

.github/workflows/02-deploy-gh-pages.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ jobs:
1616
- name: 🔄 Init Cache
1717
uses: ./.github/actions/npm-cache
1818

19-
- name: 🍼 Create pages build
20-
run: npm run deploy:pages
19+
- name: ⬇️Download build
20+
uses: actions/download-artifact@v3
21+
with:
22+
name: build
23+
path: out
2124

2225
- name: ➕ Bundle current gh-pages
2326
uses: ./.github/actions/bundle-gh-page
@@ -27,5 +30,3 @@ jobs:
2730
with:
2831
github_token: ${{ secrets.GITHUB_TOKEN }}
2932
publish_dir: ./public
30-
31-

.github/workflows/cleanup.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,24 @@ jobs:
1111
name: Clean
1212
runs-on: ubuntu-latest
1313
steps:
14+
- name: ⬇️ Checkout repo
15+
uses: actions/checkout@v3
16+
17+
- name: 🔄 Init Cache
18+
uses: ./.github/actions/npm-cache
19+
1420
- 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
21+
run: wget -q https://github.com/dbsystel/cicd-playground/tarball/gh-pages
1722
- name: ➕ Create public dir
1823
run: mkdir public
19-
shell: bash
2024
- name: 📦 Unpack Tar
21-
run: tar -xf public.tar.gz -C public --strip-components 1
22-
shell: bash
25+
run: tar -zxf gh-pages -C public --strip-components 1
26+
2327
- 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+
run: node scripts/cleanup-gh-pages.js
2829

30+
- name: 🥅 Deploy to GH-Pages
31+
uses: peaceiris/actions-gh-pages@v3
32+
with:
33+
github_token: ${{ secrets.GITHUB_TOKEN }}
34+
publish_dir: ./public

.github/workflows/default.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@ jobs:
1414
needs: [init]
1515

1616
build:
17+
uses: ./.github/workflows/01-build.yml
18+
needs: [init]
19+
20+
build-playground:
1721
uses: ./.github/workflows/01-build-playground.yml
1822
needs: [init-playground]
1923

2024
cypress:
2125
uses: ./.github/workflows/01-cypress.yml
22-
needs: [init]
26+
needs: [build]
2327

2428
deploy:
2529
uses: ./.github/workflows/02-deploy-gh-pages.yml
26-
needs: [test, cypress, build]
30+
needs: [test, cypress, build-playground]
2731

2832
publish:
2933
if: contains( github.ref, 'main')

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# CI/CD playground
2+
23
Playground for testing GitHub CI/CD
34

45
gets deployed to https://dbsystel.github.io/cicd-playground/ out of the folder `/public/`

0 commit comments

Comments
 (0)