Skip to content

Commit c202079

Browse files
authored
Refactor vite GitHub (#1)
* refactor: vite with cra, add github workflow * fix: issue with autocomplete * chore: update workflows, add typings for pokemon
1 parent d9d87be commit c202079

38 files changed

+9095
-34991
lines changed

.env.template

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# It will force the user to add an e-mail for a project
22
33

4-
5-
REACT_APP_FIREBASE_API_KEY=TODO
6-
REACT_APP_FIREBASE_AUTH_DOMAIN=TODO
7-
REACT_APP_FIREBASE_PROJECT_ID=TODO
8-
REACT_APP_FIREBASE_STORAGE_BUCKET=TODO
9-
REACT_APP_FIREBASE_MESSAGING_SENDER_ID=TODO
10-
REACT_APP_FIREBASE_APP_ID=TODO
4+
VITE_FIREBASE_API_KEY=TODO
5+
VITE_FIREBASE_AUTH_DOMAIN=TODO
6+
VITE_FIREBASE_PROJECT_ID=TODO
7+
VITE_FIREBASE_STORAGE_BUCKET=TODO
8+
VITE_FIREBASE_MESSAGING_SENDER_ID=TODO
9+
VITE_FIREBASE_APP_ID=TODO
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
name: 'Download Tar Artifact'
3+
description: 'Downloads an artifact and unzips it'
4+
inputs:
5+
name:
6+
description: 'Name for artifact'
7+
required: true
8+
path:
9+
description: 'Path for unzip'
10+
required: true
11+
runs:
12+
using: 'composite'
13+
steps:
14+
- name: ⬇ Download build
15+
uses: actions/download-artifact@v3
16+
with:
17+
name: ${{ inputs.name }}
18+
19+
- name: 📁 Manage path folder
20+
run: |
21+
if [ ! -d ${{ inputs.path }} ]; then
22+
mkdir ${{ inputs.path }}
23+
fi
24+
export amount=1
25+
export path="${{ inputs.path }}"
26+
if [[ "$path" == *\/* ]] || [[ "$path" == *\\* ]]
27+
then
28+
export slashes=$(grep -o "/" <<<"$path" | wc -l)
29+
export amount=$((amount + slashes))
30+
fi
31+
echo "##[set-output name=amount;]$(echo ${amount})"
32+
shell: bash
33+
id: manage-path-folder
34+
35+
- name: 📦 Unpack Tar
36+
run: tar -zxf ${{ inputs.name }} -C ${{ inputs.path }} --strip-components ${{ steps.manage-path-folder.outputs.amount }}
37+
shell: bash

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

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
name: "NPM Cache Action"
3+
description: "Initialize NPM Cache"
4+
inputs:
5+
nodeModulesPath:
6+
description: "Path for node_modules"
7+
required: false
8+
default: "**/node_modules"
9+
packageLockPath:
10+
description: "Path for package-lock.json"
11+
required: false
12+
default: "**/package-lock.json"
13+
outputs:
14+
cache-hit:
15+
description: "A boolean value to indicate an exact match was found for the primary key"
16+
value: ${{ steps.cache.outputs.cache-hit }}
17+
runs:
18+
using: "composite"
19+
steps:
20+
- uses: actions/cache@v3
21+
id: "cache"
22+
with:
23+
path: ${{ inputs.nodeModulesPath }}
24+
key: ${{ runner.os }}-node-${{ hashFiles(inputs.packageLockPath) }}
25+
restore-keys: |
26+
${{ runner.os }}-node-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
name: 'Upload Tar Artifact'
3+
description: 'Upload an artifact and zips it as {name}.tar.gz'
4+
inputs:
5+
name:
6+
description: 'Name for artifact'
7+
required: true
8+
path:
9+
description: 'Path to zip'
10+
required: true
11+
runs:
12+
using: 'composite'
13+
steps:
14+
- name: 📦 Pack build as tar
15+
run: tar -czf ${{ inputs.name }} ${{ inputs.path }}
16+
shell: bash
17+
18+
- name: ⬆ Upload build
19+
uses: actions/upload-artifact@v3
20+
with:
21+
name: ${{ inputs.name }}
22+
path: ${{ inputs.name }}

.github/workflows/00-init.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
name: Init Workflow
3+
4+
on:
5+
workflow_call:
6+
7+
jobs:
8+
init:
9+
name: Init
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: 🛑 Cancel Previous Runs
13+
uses: styfle/[email protected]
14+
15+
- name: ⬇ Checkout repo
16+
uses: actions/checkout@v3
17+
18+
- name: 🔄 Init Cache
19+
uses: ./.github/actions/npm-cache
20+
id: 'npm-cache' # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
21+
22+
- name: 📥 Download deps default-npm-cache
23+
if: steps.npm-cache.outputs.cache-hit != 'true'
24+
uses: bahmutov/npm-install@v1
25+
with:
26+
install-command: npm ci --ignore-scripts

.github/workflows/01-build.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
name: Build Workflow
3+
4+
on:
5+
workflow_call:
6+
7+
jobs:
8+
build:
9+
name: Build
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: ⬇ Checkout repo
13+
uses: actions/checkout@v3
14+
15+
- name: 🔄 Init Cache
16+
uses: ./.github/actions/npm-cache
17+
18+
- name: 🌱 Setup environment
19+
run: |
20+
touch .env
21+
echo "VITE_FIREBASE_API_KEY=${{secrets.VITE_FIREBASE_API_KEY}}" >> .env
22+
echo "VITE_FIREBASE_AUTH_DOMAIN=${{secrets.VITE_FIREBASE_AUTH_DOMAIN}}" >> .env
23+
echo "VITE_FIREBASE_PROJECT_ID=${{secrets.VITE_FIREBASE_PROJECT_ID}}" >> .env
24+
echo "VITE_FIREBASE_STORAGE_BUCKET=${{secrets.VITE_FIREBASE_STORAGE_BUCKET}}" >> .env
25+
echo "VITE_FIREBASE_MESSAGING_SENDER_ID=${{secrets.VITE_FIREBASE_MESSAGING_SENDER_ID}}" >> .env
26+
echo "VITE_FIREBASE_APP_ID=${{secrets.VITE_FIREBASE_APP_ID}}" >> .env
27+
28+
- name: 🔨 Build
29+
run: npm run build
30+
31+
- name: ⬆ Upload build
32+
uses: ./.github/actions/upload-tar-artifact
33+
with:
34+
name: build-output
35+
path: build

.github/workflows/02-hosting.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
name: Hosting Workflow
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
channelId:
8+
description:
9+
"The ID of the channel to deploy to. If you leave this blank,
10+
a preview channel and its ID will be auto-generated per branch or PR."
11+
required: false
12+
type: string
13+
14+
jobs:
15+
hosting:
16+
name: Hosting
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: ⬇ Checkout repo
20+
uses: actions/checkout@v3
21+
22+
- name: ⬇ Download build
23+
uses: ./.github/actions/download-tar-artifact
24+
with:
25+
name: build-output
26+
path: build
27+
28+
- uses: FirebaseExtended/action-hosting-deploy@v0
29+
with:
30+
repoToken: "${{ secrets.GITHUB_TOKEN }}"
31+
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_POKEMON_ZOGGEN }}"
32+
projectId: pokemon-zoggen
33+
channelId: ${{ inputs.channelId }}

.github/workflows/pull-request.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file was auto-generated by the Firebase CLI
2+
# https://github.com/firebase/firebase-tools
3+
4+
name: Deploy to Firebase Hosting on PR
5+
"on": pull_request
6+
jobs:
7+
init:
8+
uses: ./.github/workflows/00-init.yml
9+
10+
build:
11+
uses: ./.github/workflows/01-build.yml
12+
needs: [ init ]
13+
secrets: inherit
14+
15+
preview:
16+
if: "${{ github.event.pull_request.head.repo.full_name == github.repository }}"
17+
uses: ./.github/workflows/02-hosting.yml
18+
needs: [ build ]
19+
secrets: inherit

.github/workflows/push-main.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This file was auto-generated by the Firebase CLI
2+
# https://github.com/firebase/firebase-tools
3+
4+
name: Deploy to Firebase Hosting on merge
5+
'on':
6+
push:
7+
branches:
8+
- main
9+
jobs:
10+
init:
11+
uses: ./.github/workflows/00-init.yml
12+
13+
build:
14+
uses: ./.github/workflows/01-build.yml
15+
needs: [ init ]
16+
secrets: inherit
17+
18+
deploy:
19+
uses: ./.github/workflows/02-hosting.yml
20+
with:
21+
channelId: live
22+
needs: [ build ]
23+
secrets: inherit

index.html

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html style="height: 100%" lang="de">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<meta name="theme-color" content="#000000" />
8+
<meta
9+
name="description"
10+
content="Freunde die zusammen Pokemon spielen, was gibt es schöneres."
11+
/>
12+
<link
13+
rel="preload"
14+
as="style"
15+
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
16+
/>
17+
<link rel="apple-touch-icon" href="/logo192.png" />
18+
<link rel="manifest" href="/manifest.json" />
19+
<title>Pokemon Zoggen</title>
20+
</head>
21+
<body style="height: 100%">
22+
<noscript>You need to enable JavaScript to run this app.</noscript>
23+
<div id="root" style="height: 100%"></div>
24+
<script type="module" src="/src/index.tsx"></script>
25+
</body>
26+
</html>

0 commit comments

Comments
 (0)