Skip to content

Merge pull request #3 from CIAT-DAPA/develop #32

Merge pull request #3 from CIAT-DAPA/develop

Merge pull request #3 from CIAT-DAPA/develop #32

Workflow file for this run

name: React Build, Release, and Deploy to GitHub Pages
on:
push:
branches: [ "stage" ]
tags:
- 'v*'
permissions:
contents: write
jobs:
build-release-and-deploy:
name: Build React App, Create Release, and Deploy to GitHub Pages
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v3
# Set up Node.js environment
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18' # Cambia según la versión que necesite tu proyecto
# Install dependencies, set up .env, and build the project
- name: Install and Build 🔧
env:
CI: false
REACT_APP_COUNTRY_ID: ${{ secrets.REACT_APP_COUNTRY_ID }} # Variable secreta configurada en GitHub
run: |
cd ./src
echo "REACT_APP_COUNTRY_ID=${{ env.REACT_APP_COUNTRY_ID }}" > .env
npm ci
npm run build
# Zip the build folder for the release
- name: Prepare Build Artifact
run: zip -r react-build.zip ./src/build
# Upload the artifact to the workflow
- name: Upload Build Artifact
uses: actions/upload-artifact@v3
with:
name: react-build
path: ./src/react-build.zip
# Generate the tag name for the release
- name: Generate Tag Name
id: tagger
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_branches: stage
with_v: true
default_bump: patch
# Create the release in GitHub
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tagger.outputs.new_tag }}
release_name: Release ${{ steps.tagger.outputs.new_tag }}
body: Build release for ${{ steps.tagger.outputs.new_tag }}
draft: false
prerelease: false
# Upload the build artifact to the release
- name: Upload Build to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: react-build.zip
asset_name: react-build.zip
asset_content_type: application/zip
# Deploy to GitHub Pages
- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages # Branch to deploy to
folder: ./src/build # Folder to deploy
merge-to-main:
needs: build-release-and-deploy
name: Merge Stage to Main
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v3
with:
ref: stage # Checkout the stage branch
# Merge stage into main
- name: Merge Stage into Main
uses: devmasx/[email protected]
with:
type: now
head_to_merge: stage
target_branch: main
github_token: ${{ secrets.GITHUB_TOKEN }}