-
Notifications
You must be signed in to change notification settings - Fork 9
93 lines (80 loc) · 3.26 KB
/
deploy-unicorn.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Deploy Unicorn
## The unicorn is public available at elements.inovex.de/unicorn/<BRANCH-NAME>.
on:
workflow_call:
jobs:
changeDetection:
runs-on: ubuntu-latest
outputs:
hasChanges: ${{ steps.evaluation.outputs.hasChanges }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref || github.ref }}
fetch-depth: 0
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
# Cache handling to determine the last commit id of unicorn deployment
# 1. Load cache file
# 2. Read SHA from file
# 3. Check if commit SHA has changed
# 4. Update cache if necessary
- name: Get last commit info file from cache
id: sha-cache
uses: actions/cache@v3
with:
path: last_commit_sha.txt
key: last-commit-${{ env.GITHUB_REF_NAME_SLUG_URL }}-${{ github.run_id }}
restore-keys: last-commit-${{ env.GITHUB_REF_NAME_SLUG_URL }}
- name: Read commit sha from file
id: last-commit
run: test -f last_commit_sha.txt
&& echo "sha=$(cat last_commit_sha.txt)" >> $GITHUB_OUTPUT
|| echo "sha=${{ github.event.pull_request.base.sha || github.event.before }}" >> $GITHUB_OUTPUT
- name: Save commit SHA to cache
id: current-commit
run: echo "${{ github.event.pull_request.head.sha || github.sha }}" > last_commit_sha.txt
&& echo "sha=${{ github.event.pull_request.base.sha || github.sha }}" >> $GITHUB_OUTPUT
- name: Get changed files
if: steps.current-commit.outputs.sha != steps.last-commit.outputs.sha
id: changed-files
uses: tj-actions/changed-files@v41
with:
sha: ${{ steps.current-commit.outputs.sha }}
base_sha: ${{ steps.last-commit.outputs.sha }}
files: |
packages/elements
packages/storybook
- name: Print all changed files
if: steps.current-commit.outputs.sha != steps.last-commit.outputs.sha
run: echo '${{ toJSON(steps.changed-files.outputs.all_changed_and_modified_files) }}'
- name: Check if storybook or elements was changed
if: steps.changed-files.outputs.all_changed_and_modified_files != ''
|| steps.current-commit.outputs.sha == steps.last-commit.outputs.sha
id: evaluation
run: echo "hasChanges=true" >> $GITHUB_OUTPUT
deploy:
runs-on: ubuntu-latest
if: ${{ needs.changeDetection.outputs.hasChanges == 'true' }}
needs: changeDetection
environment:
name: github-pages
url: https://elements.inovex.de/unicorn/${{ env.GITHUB_REF_NAME_SLUG_URL }}
steps:
- uses: actions/checkout@v3
with:
ref: pages
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
- name: Download Storybook artifact
uses: actions/download-artifact@v3
with:
name: storybook
path: storybook-dist
- name: Deploy to Github Pages 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: ./storybook-dist
target-folder: unicorn/${{ env.GITHUB_REF_NAME_SLUG_URL }}
commit-message: Deploying unicorn ${{ env.GITHUB_REF_NAME_SLUG_URL }} 🦄
force: true