Home About Notes

Automating with GitHub actions

Jan 17, 2023

As part of my current workflow I wanted to automate some task from github actions. Here is the overview of some of the things I learnt doing this.

When you checkout you can set the user to to be the github actions bot

- uses: actions/checkout@v3
- run: |
    git config user.name github-actions
    git config user.email github-actions@github.com

Easily set environment variables

- name: Set Date
  id: date
  run: |
    echo "YEAR=$(date +"%Y")" >> $GITHUB_ENV
    echo "WEEK=$(date +"%W")" >> $GITHUB_ENV

- name: Another step
  id: another_step 
  run: |
    echo "${{ env.WEEK }}"

GitHub CLI

GitHub CLI is preinstalled on all GitHub-hosted runners.

- name: Create Pull request
  run: |
    ...
    gh pr create --title "Created ${{ env.YEAR }} ${{ env.WEEK }}" --body "PR description"