Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

GitHub actions not passing environment variables to Vite build

I am trying to create a GitHub action to deploy a React Application on a S3 Bucket. The issues that I am having are related to the environment variables being backed during build with Vite.

When all the checks on the GitHub action pass and the app is deployed, seems like none of the ENVS have been passed in.

name: Upload to S3

on:
  pull_request:
  push:
    branches:
      - dev
jobs:
  build:
    runs-on: ubuntu-latest
    
    strategy:
      matrix:
        node-version: [14.x]

    steps:
      - uses: actions/checkout@v3
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v2
        with:
          aws-region: ${{ secrets.AWS_REGION }}
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        env:
          VITE_APP_BASE_URL: ${{ secrets.VITE_APP_BASE_URL }}
          AWS_S3_BUCKET: ${{ secrets.AWS_REBRAND_BUCKET_NAME }}
          VITE_APP_ALGOLIA_APP_ID:  ${{ secrets.VITE_APP_ALGOLIA_APP_ID }}
          VITE_APP_ENVIRONMENT: development
      
      - name: Yarn Install
        run: yarn install
      - name: Yarn Build
        run: yarn build
      - name: Deploy app build to S3 bucket
        run: aws s3 sync ./build/ s3://${{ secrets.AWS_REBRAND_BUCKET_NAME }} --delete

my yarn build command is just "build": "vite build". Something strange I have noticed is that the configure secrtes such as aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} are passed correctly.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’m not sure why the rest of my envs are not passed at all. Is my yaml not correct?

>Solution :

You have placed the environment variables under the Configure AWS Credentials step. You should move these variables to the Yarn Build step, as that is where they are needed. Another option is to move them to the job level to make them accessible at each step.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading