4 things you didn’t know you could do with GitHub Actions

GitHub Actions is a powerful platform that empowers your team to go from code to cloud, all from the comfort of your repositories. In this post, I’ll walk through a…

|
| 4 minutes

GitHub Actions is a powerful platform that empowers your team to go from code to cloud, all from the comfort of your repositories. In this post, I’ll walk through a few examples of how you can use GitHub Actions to automate and orchestrate your DevOps pipeline today.

Compress images for the web with GitHub Actions

Now there’s something that I always do when uploading images to my bdougie.live site, which is nothing. If you have been following my GitHub Actions series on Twitter, you know I am always looking for quick wins to improve my site’s performance, and Image Actions is just the trick.

The GitHub Marketplace is a directory to find and add tools for helping to build and grow your development workflow. There I was able to search for image compression; Image Actions returned as the top result.

Watch how below, or check out my written walkthrough.

Generate semantic-release notes with GitHub Actions

I saw a Tweet recently about doing semantic releases with GitHub Actions. When I went to respond, I noticed there were already answers all pointing to semantic-release. One of the benefits of GitHub Actions is that the majority of its users open source their workflows by default. I was able to kick start my workflow for keeping up with releases thanks to code from benmvp, a GitHub user and keynote speaker.

name: Release

on:
  push:
    branches:
      - master

jobs:
  main:
    name: NPM Release
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v1

      - name: Use Node v12
        uses: actions/setup-node@v1
        with:
          node-version: 12

      - name: Install dependencies
        run: npm ci

      - name: Double check unit tests
        run: npm test
        env:
          CI: true

      - name: Double check integration tests
        run: npm run integrate
        env:
          CI: true

      - name: Build package
        run: npm run build

      - name: Release new version to NPM
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: npx semantic-release

If you take a look at that workflow, you can see at the bottom that he’s using the npx command to leverage semantic-release directly with its CLI. GitHub Actions workflows allow you to run set runner environments and run shell commands. That solves the one problem, but I’m a big fan of actually automating my changelog as well.

I leverage actions to generate my release notes for projects. I discovered that it provides a changelog and bumps the version number in package.json file.

Watch above, or check out my DEV post.

Run your GitHub Actions like a makefile

When developing GitHub Action workflows, you might find yourself pushing arbitrary commits to trigger the logs. Instead, use the community built tools available to you for debugging locally, like nektos/act.

When you run act, it reads in your GitHub Actions from .github/workflows/ and determines the set of actions that need to be run. It uses the Docker API to either pull or build the necessary images, as defined in your workflow files and finally determine the execution path based on the defined dependencies. Once it has the execution path, it then uses the Docker API to run containers for each action based on the images prepared previously. The environment variables and filesystem are all configured to match what GitHub provides.

Watch above, or check out my DEV post.

Bring your own environment for GitHub Action Workflows

For secrets stored at the environment level, you can enable required reviewers to control access to the secrets. A workflow job cannot access environment secrets until the required approvers approve.

Screenshot of UI for Actions secret configuration

For secrets stored at the environment level, you can enable required reviewers to control access to the secrets. A workflow job cannot access environment secrets until the required approvers approve.

Watch above, or check out my DEV post.

More tips

To learn more about using GitHub Actions, check out the GitHub Documentation. If you have found this post helpful, I have 24 more tips, all of which you can find on our DEV space.

Written by

Related posts