Things I learned about GitHub username, workflows and GitHub Actions

Today I learned to setup GitHub Actions to continuously integrate (build and test) my blog, along the way I encountered some blockers so I'm putting everything noteworthy in this post.

GitHub commit not showing my avatar

First, after I pushed a commit to GitHub I noticed the commit was labeled with a generic GitHub icon instead of my normal avatar. Then I remembered recently I changed my GitHub username, so if you ever change your username on GitHub remember your username is attached to a "noreply" email provided GitHub that is part of your local .gitconfig file. On Windows this file is located in C:\Users\[username]\ folder. After updating my username in this file, things went back to normal as you can see the next commit is showing my regular avatar.

GitHub commit not showing my avatar
GitHub commit not showing my avatar

According to this doc about your GitHub email. I don't remember when I joined GitHub and there doesn't seem to be away to find out, the email in my .gitconfig is without the ID but in my settings on GitHub there is one with the ID. Since the one without the ID worked I didn't bother trying out the one with ID.

If you created your GitHub account after July 18, 2017, your GitHub-provided no-reply email address is a seven-digit ID number and your username in the form of ID+username@users.noreply.github.com. If you created your GitHub account prior to July 18, 2017, your GitHub-provided no-reply email address is your username in the form of username@users.noreply.github.com. You can get an ID-based GitHub-provided no-reply email address by selecting (or deselecting and reselecting) Keep my email address private in your email settings.

GitHub workflows changes cannot be pushed

GitHub Actions basically involves creating a .yml file and putting it in a workflows folder inside your .github folder in your project. After I created my yml file and put it inside the workflows folder, I discovered that I could not push these changes to GitHub. I encountered the following error and I tried from both Visual Studio and the command line.

Git cannot push my changes to GitHub workflows
Git cannot push my changes to GitHub workflows

 ! [remote rejected] build-375-add-github-actions -> build-375-add-github-actions (refusing to allow an OAuth App to create or update workflow `.github/workflows/ci.yml` without `workflow` scope)

error: failed to push some refs to 'https://github.com/rayrfan/Fanray.git'

I resolved this issue by following this StackOverflow answer. The steps are: on Windows search for "Credential Manager", and delete all the entries related to github in the Windows Credentials section. After that push again from Visual Studio, and it will ask you to enter your GitHub credentials again inside a browser window, and as part of that it will ask you to give permission to add the Credential Manager as an Authorized OAuth Apps on GitHub.  Finally, you can now push changes related to workflows to GitHub from your local successfully.

Credentials Manager - Windows Credentials
Credentials Manager - Windows Credentials

Setting up GitHub Actions - yml and status badge

Now coming back to GitHub Actions, below is my ci.yml file and here are the docs on Introduction to GitHub Actions that explains what each item in this file does. I basically want the following to happen

  • Run my ci.yml whenever there is a push to the "dev", any "feature" or "fix" branches, or if there are PRs on "main" and "dev" branches.
  • Run build and test for all the latest versions of Ubuntu, Windows and Macos.
name: Build & Test

on:
  push:
    branches: [ dev, feature-*, fix-* ]
  pull_request:
    branches: [ main, dev ]

jobs:
  build:

    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]

    steps:
    - uses: actions/[email protected]
    - name: Setup .NET
      uses: actions/[email protected]
      with:
        dotnet-version: 5.0.x
    - name: Restore dependencies
      run: dotnet restore
      
    - name: Build
      run: dotnet build --no-restore
    - name: Test
      run: dotnet test --no-build --verbosity normal

Interestingly, checking in my ci.yml file the first try, Macos passed without any issues, while Ubuntu build failed on tests and the Windows build failed on package restore. So, for now to keep things moving I removed Windows and Ubuntu from the script.

Next I looked into how to setup a GitHub workflow status badge for me README.md. Here is the HTML snippet of my status badge icon link. This part will likely need revise once I have more workflows.

<a href="https://github.com/rayrfan/Fanray/actions/workflows/ci.yml">
  <img src="https://github.com/rayrfan/Fanray/actions/workflows/ci.yml/badge.svg" alt="GitHub Actions">
</a>