Skip to content

Latest commit

 

History

History
122 lines (81 loc) · 5.4 KB

01-My-first-workflow.md

File metadata and controls

122 lines (81 loc) · 5.4 KB

🔨 Hands-on: My first workflow

In this hands-on lab your will create your first GitHub Actions Workflow and learn how you can use Actions to automate tasks in your software development lifecycle. If you like more background information, please refer to the GitHub Actions pages on GitHub Docs. Good luck! 👍

This hands on lab consists of the following steps:

Creating a repository

Go to The ActionsFundamentals repository in the ps-actions-sandbox organization and click Use this template:

2022-09-18_11-24-58

Select your GitHub user as the owner and name the repository. Leave the repo public to have unlimited action minutes:

2022-09-18_11-25-57

Continue now in the new repository.

Creating the workflow

Go to Actions | New Workflow and click on set up a workflow yourself.

  1. Rename the file main.yml in the .github/workflows directory to github-actions-demo.yml.

image

  1. Remove the template content - we want to create the workflow from scratch.
  2. Click Ctrl+Space and select name as the first element:

image

  1. Set the workflow name to GitHub Actions Demo:
name: GitHub Actions Demo
  1. Add the triggers to the worklow with the help of Ctrl+Space and the documentation. We want the workflow to trigger:
  • on every push to the main branch, but not when there are changes to files in the .github folder.
  • on every pull request with main as the base branch
  • Every sunday at 6:15 UTC
  • Manually
Solution
on:
  push:
    branches: [ main ]
    paths-ignore: [.github/**]
  pull_request:
    branches: [ main ]
  schedule:
    - cron: '15 6 * * 0'
  workflow_dispatch:
  1. Create a job Build that runs on the latest Ubuntu image on GitHub hosted runners. Check the documentation of the virtual environments what label to use and what version it is. The job should do the following things:
  • Output the name of the event that triggered the workflow
  • Output the name of the branch that the repository is currently referencing
  • List all files in the repository
Solution
jobs:
  Build:
    runs-on: ubuntu-latest
    steps:
      - run: |
          echo "🎉 The job was triggered by event: ${{ github.event_name }}"
          echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ."

      - uses: actions/checkout@v3.3.0

      - name: List files in the repository
        run: |
          echo "The repository ${{ github.repository }} contains the following files:"
          tree
  1. Commit the workflow file - and trigger the workflow manually. It should not run automatically if your path filter works. Go to Action, select GitHub Actions Demo and Run workflow:

image

Viewing your workflow results

  1. Click on your workflow run:

image

  1. Click on the job 'Build':

image

  1. Expand Set up job and note the log with the line number (line numbers are links). Check the information about the virtual environment and included software:

image

  1. Expand your jobs and check that the output was correct.

image

  1. Verify your other triggers by modifying the README.md file:
  • Modify and commit: triggers build (push)
  • Modify and add [skip ci] (not triggering the workflow):

image

  • Modify the README.md file and create a pull request (trigger: pull_request)

Summary

In this hands-on you've learned to create you first workflow with triggers, jobs, steps, and expressions. Next you will write your first GitHub Action.