Reputation:
I have a little vite project for a single page application on GitHub.
The vite app consumes a REST API.
Due to the nature of vite all environment variables are compiled into the output during npm run build
.
I want a build process like this:
npm run build
In my understanding I have to upload the artifact from step 1 and download it in step 2, but this means that everyone that can see the artifacts can see the URL of the production server. I think it is possible to delete the artifact after downloading it from step 1, but there are two problems here:
Does anyone know how to achieve this workflow without leaking the production URL?
Maybe I did not find the correct GitHub Actions documentation page.
Upvotes: 1
Views: 825
Reputation: 1
Sorry for the extremely late response, as you might have already figured this out, but here’s a solution anyway :)
GitHub’s Cache action can also save files, but it does so without uploading it as an artifact, which I think we were both looking for. So here’s an example workflow I put together:
jobs:
save-files:
name: Save files
runs-on: ubuntu-latest
outputs:
current_date: ${{ steps.get_date.outputs.CURRENT_DATE }}
steps:
- name: Get date
id: get_date
run: |
echo "CURRENT_DATE=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT
- name: Save source
uses: actions/cache/save@v3
with:
path: ./generated
key: dist-files-${{ steps.get_date.outputs.CURRENT_DATE }}
build:
name: Load files
runs-on: ubuntu-latest
needs: [save-files]
steps:
- name: Restore cached source
uses: actions/cache/restore@v3
with:
path: ./generated
key: dist-files-${{ needs.save-files.outputs.current_date }}
The workflow fails if the cache already exists, which is why I used the timestamp of saving to give each workflow run a unique cache name. I hope this helps!
Upvotes: 0