string #160
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
name: Deploy Frontend | |
env: | |
REACT_APP_API_URL: ${{ vars.REACT_APP_API_URL }} | |
REACT_APP_ENVIRONMENT: ${{ vars.REACT_APP_ENVIRONMENT }} | |
CORS_ALLOWED_ORIGINS: ${{ vars.CORS_ALLOWED_ORIGINS }} | |
on: | |
push: | |
branches: [main, staging, frontend] | |
paths: | |
- 'frontend/**' | |
- '.github/workflows/deploy_frontend.yml' | |
workflow_dispatch: | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pages: write # Added for GitHub Pages deployment | |
id-token: write # Necessary for actions/deploy-pages | |
environment: | |
name: ${{ github.ref == 'refs/heads/main' && 'prod' || 'staging' }} | |
url: ${{ steps.deployment.outputs.page_url }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Debug REACT_APP_API_URL | |
shell: bash | |
run: | | |
echo -e "\e[32m@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\e[0m" | |
echo -e "\e[32mREACT_APP_API_URL=${REACT_APP_API_URL}\e[0m" | |
echo -e "\e[32mREACT_APP_ENVIRONMENT=${REACT_APP_ENVIRONMENT}\e[0m" | |
echo -e "\e[32mCORS_ALLOWED_ORIGINS=${CORS_ALLOWED_ORIGINS}\e[0m" | |
env | |
echo $(env | grep ACTIONS_RUNTIME_TOKEN) | |
# exit 1 # Commented out to allow the workflow to continue | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Print Environment Variables and Secrets | |
shell: bash | |
env: | |
REACT_APP_ENVIRONMENT: ${{ env.REACT_APP_ENVIRONMENT }} | |
run: | | |
echo -e "\e[32mREACT_APP_API_URL=${REACT_APP_API_URL}\e[0m" | |
echo -e "\e[32mREACT_APP_ENVIRONMENT=${REACT_APP_ENVIRONMENT}\e[0m" | |
env | |
echo ACTIONS_RUNTIME_TOKEN=$(env | grep ACTIONS_RUNTIME_TOKEN) | |
- name: Install dependencies | |
shell: bash | |
run: | | |
cd frontend | |
npm ci 2>&1 || (echo -e "\e[31mInstall dependencies step failed.\e[0m" && exit 1) | |
- name: Build | |
shell: bash | |
run: | | |
npm install env-cmd or npm install -g env-cmd | |
cd frontend | |
TIMESTAMP=$(date +"%Y%m%d_%H%M%S") | |
export REACT_APP_BUILD_TIME=$(TZ=America/Argentina/Buenos_Aires date +"%Y-%m-%d %H:%M:%S") | |
echo -e "\e[32mBuilding with environment variables:\e[0m" | |
env | |
echo -e "\e[32m$(pwd)\e[0m" | |
# Create .env file with environment variables for the build | |
echo "REACT_APP_BUILD_TIME=${TIMESTAMP}" > .env | |
echo "REACT_APP_API_URL=${REACT_APP_API_URL}" >> .env | |
echo "REACT_APP_ENVIRONMENT=${REACT_APP_ENVIRONMENT}" >> .env | |
echo -e "\e[32mCreated .env file for npm run build.\e[0m" | |
echo .env contents: | |
cat .env | |
npm run build || (echo -e "\e[31mBuild step failed.\e[0m" && exit 1) | |
rm -f .env | |
echo -e "\e[32mDeleted .env file after build.\e[0m" | |
- name: Setup Pages | |
uses: actions/configure-pages@v4 | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: './frontend/build' | |
- name: Deploy to GitHub Pages | |
if: ${{ !env.ACT }} # Only run this step if NOT in act | |
id: deployment | |
uses: actions/deploy-pages@v4 | |
- name: Build Succeeded | |
if: success() | |
run: echo -e "\e[32mBuild succeeded.\e[0m" | |
- name: Build Failed | |
if: failure() | |
shell: bash | |
run: | | |
echo -e "\e[31mBuild failed.\e[0m" | |
exit 1 |