Copy env files from host where actions runner is located

I’m new to actions. I’m trying to get CI/CD setup for my node / express app. I have a few .env files that don’t get checked into the repo that need to be copied in from the host where the self-hosted actions runner is. I’m missing something… the following errors out with permissions issues with our without sudo. After this I intend to building and running a container but I need my .env info copied in first before that step. Any help would be appreciated.

jobs:
  build:

    runs-on: self-hosted

    strategy:
      matrix:
        node-version: [14.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: yarn install --frozen-lockfile
    - name: Copy in root env file
      run: sudo ~/server_js/vd_be_env_files/root_env ./.env
    - name: Copy in prisma env file
      run: sudo ~/server_js/vd_be_env_files/prisma_env ./prisma/.env

ok… this was just understanding how to organize my actions / jobs / steps better.

Working example:

name: Node.js CI

on:
  workflow_dispatch:
  push:
    branches: [ master ]
jobs:
  build:
    runs-on: self-hosted
    strategy:
      matrix:
        node-version: [14.x]
    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - run: yarn install --frozen-lockfile
  copy_env_files:
    runs-on: self-hosted
    needs: build
    if: success()
    steps:
    - run: cp ~/server_js/vd_be_env_files/root_env ./.env

1 Like