Bootstrap FreeKB - GitHub Actions - Getting Started with GitHub Actions
GitHub Actions - Getting Started with GitHub Actions

Updated:   |  GitHub Actions articles

GitHub Actions can be used to do something whenever something happens in one of your GitHub repositories, most often when there is a pull request or when a pull request has been reviewed and merged into the master branch. In GitHub lingo, an event occurs which will trigger an action.

In your GitHub repository, select the Actions tab and then create a YAML file such as main.yml. This YAML file should be located in the .github/workflows directory such as .github/workflows/main.yml.

In the YAML file there is an "on" section. These are the events that will trigger the GitHub action. In this example, when there is a push to the main branch, the GitHub action will be triggered.

on:
  push:
    branches:
      - main

 

Here is the full YAML file.

name: GitHub Action - foo repository
run-name: ${{ github.workflow }} run by ${{ github.actor }}
on:
  push:
    branches:
      - main
jobs:
  github-action-job:
    runs-on: ubuntu-latest
    steps:
      - run: echo "This job was triggered by github.event_name -> ${{ github.event_name }}"
      - run: echo "This job is running on runner.os -> ${{ runner.os }}"
      - run: echo "github.ref -> ${{ github.ref }} (e.g. branch name)"
      - run: echo "github.repository -> ${{ github.repository }}"      
      - name: Checking out the repository code . . .
        uses: actions/checkout@v4
      - run: echo "github.repository ${{ github.repository }} has been cloned to runner ${{ runner.os }}"
      - name: List files in the repository
        run: |
          ls ${{ github.workspace }}     
      - run: echo "job.status -> ${{ job.status }}"

 

To see if the GitHub Action will be trigger, perhaps make a trivial change to a file in your repository and push the commit to your main branch. This should trigger the GitHub Action.

Go back to the home page of your GitHub repository and select the Actions tab. In the left panel, select GitHub Actions Demo. Select <your name> is testing out GitHub Actions and select Explore-GitHub-Actions. Something like this should be displayed.




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter adb24c in the box below so that we can be sure you are a human.