Artefacts #13
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: Artefacts | |
on: workflow_dispatch | |
# environment variable | |
env: | |
MONGODB_DB_NAME: my-mongo-dba | |
jobs: | |
build-job: | |
runs-on: ubuntu-latest | |
env: | |
JOB_LEVEL_VAR_NAME: this environment variable is defined at job level | |
outputs: | |
# GitHub action output - set var | |
script-file: "${{ steps.publish_step_id.outputs.script-file-var }}" | |
steps: | |
- name: Get Code | |
uses: actions/checkout@v3 | |
- name: Environment Variable Interpolation | |
run: | | |
echo $MONGODB_DB_NAME | |
echo $JOB_LEVEL_VAR_NAME | |
echo ${{ env.MONGODB_DB_NAME }} | |
env | |
- name: Test env secret | |
run: | | |
echo ${{ secrets.test_env_secret }} | |
# cache depedencies for npm | |
- name: Cache Dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.npm | |
key: deps-node-modules-${{ hashFiles('**/package-lock.json') }} | |
- name: Install Dependencies | |
run: npm ci | |
- name: Run tests | |
run: npm test | |
- name: Build website | |
run: npm run build | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist-files | |
path: | | |
dist | |
package.json | |
# GitHub action output - set var | |
- name: Publish JS filename | |
id: publish_step_id | |
run: find dist/assets/*.js -type f -execdir echo 'script-file-var={}' >> $GITHUB_OUTPUT ';' | |
deploy-job: | |
needs: build-job | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get Code | |
uses: actions/checkout@v4 | |
# cache depedencies for npm | |
- name: Cache Dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.npm | |
key: deps-node-modules-${{ hashFiles('**/package-lock.json') }} | |
- name: Environment Variable Interpolation | |
run: echo $MONGODB_DB_NAME; echo $JOB_LEVEL_VAR_NAME | |
- name: Install Dependencies | |
run: npm ci | |
- name: Get build artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist-files | |
- name: Output contents | |
run: ls | |
- name: Output filename | |
run: echo "${{ needs.build-job.outputs.script-file }}" |