Update workflow to generate a build file
In this step, you will modify the workflow file to simulate a build process. You will add a step that creates a dist directory and a dummy artifact file.
- On your GitHub repository page for
github-actions-demo, click the green Code button.
- Ensure the HTTPS tab is selected and copy the URL. It should look like
https://github.com/your-username/github-actions-demo.git.
- Open the terminal in the LabEx environment. The default path is
~/project.
- Use the
git clone command to download the repository. Replace your-username with your actual GitHub username.
cd ~/project
git clone https://github.com/your-username/github-actions-demo.git
Example Output:
Cloning into 'github-actions-demo'...
remote: Enumerating objects: X, done.
remote: Counting objects: 100% (X/X), done.
remote: Total X (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (X/X), done.
- Navigate into the cloned repository:
cd ~/project/github-actions-demo
-
Create a new workflow file .github/workflows/upload-artifacts.yml using the WebIDE editor. You can find the file in the file explorer on the left side under project/github-actions-demo/.github/workflows/.
-
Start by creating the basic workflow structure. Add the workflow name and trigger:
name: Upload Artifacts
on: [push]
- Add the jobs section and define the build job with its runner:
jobs:
build:
runs-on: ubuntu-latest
- Add the steps section. First, add the checkout step:
steps:
- uses: actions/checkout@v4
- Add the Node.js setup step:
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- Add the step to install dependencies:
- name: Install dependencies
run: npm install
- Add the build step that creates the
dist directory and a file inside it:
- name: Build project
run: |
mkdir dist
echo "This is the build artifact" > dist/build.txt
- Add the test step:
- name: Run tests
run: npm test
Your complete file should now look like this:
name: Upload Artifacts
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
run: npm install
- name: Build project
run: |
mkdir dist
echo "This is the build artifact" > dist/build.txt
- name: Run tests
run: npm test
Explanation
mkdir dist: Creates a directory named dist.
echo ... > dist/build.txt: Creates a simple text file inside dist to simulate a compiled asset.
Save the file (Ctrl+S or Cmd+S) after making changes.