-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added JavaScript reactjs build template to the repository
- Loading branch information
vazzanag
committed
Apr 9, 2024
1 parent
0a34869
commit 6ded5da
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: React JS Deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- "**generated-build_**" | ||
pull_request: | ||
branches: | ||
- "**generated-build_**" | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
generate-and-deploy: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Create React App | ||
run: npx create-react-app my-app | ||
|
||
- name: Find and rename generated code file | ||
run: | | ||
generated_file=$(find . -type f -name 'generated_code_*.js') | ||
if [ -n "$generated_file" ]; then | ||
mv "$generated_file" generated_code.js | ||
fi | ||
- name: Replace existing app.js with generated code | ||
run: | | ||
if [ -f "generated_code.js" ]; then | ||
cat generated_code.js > my-app/src/App.js | ||
fi | ||
# Remove the generated code file | ||
rm generated_code.js | ||
- name: Build React app | ||
run: | | ||
cd my-app | ||
npm install | ||
npm run build | ||
- name: Commit and push changes | ||
if: success() | ||
run: | | ||
git config --global user.email "placeholder" | ||
git config --global user.name "placeholder" | ||
git add . | ||
git commit -m "Update app.js with generated code and build React app" | ||
git push origin ${{ github.ref_name }} | ||
- name: Deploy 🚀 | ||
id: deploy | ||
uses: JamesIves/github-pages-deploy-action@v4 | ||
with: | ||
folder: my-app/build # The folder containing the built React app | ||
branch : github-pages-${{ github.ref_name }} # The branch the action should deploy to. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
import React, { useState } from 'react'; | ||
|
||
const App: React.FC = () => { | ||
// State to store the user's name | ||
const [name, setName] = useState(''); | ||
|
||
// Function to handle changes to the input value | ||
const handleChange = (event) => { | ||
setName(event.target.value); | ||
}; | ||
|
||
// Function to clear the current name | ||
const handleClear = () => { | ||
setName(''); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<input | ||
type="text" | ||
value={name} | ||
onChange={handleChange} | ||
onBlur={handleClear} | ||
/> | ||
<p>{name}</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; | ||
|