Github Actions [Update]!

NOTE: Thanks @HugoGresse for giving feedback on my first post, it eventually led to this one! I owe you one 🍻

Well, since September 2019, the old Github Actions Workflow HCL syntax is not relevant anymore, so my previous blog post is deprecated.

Here is how I migrated to the new richer YAML syntax.

HCL to YAML

There is documentation available.

This is the current workflow for this blog:

workflow "Build, and Test on push" {
  on = "push"
  resolves = [
    "Send Push Notification",
    "Build Blog",
    "Cypress E2E Tests"
  ]
}

action "Clean Install" {
  uses = "actions/npm@master"
  args = "ci"
}

action "Build Blog" {
  uses = "actions/npm@master"
  needs = ["Clean Install"]
  args = "run build"
}

action "Cypress E2E Tests" {
  uses = "bartlett705/npm-cy@master"
  needs = ["Clean Install"]
  args = "test"
}

action "Send Push Notification" {
  uses = "techulus/push-github-action@master"
  secrets = ["API_KEY"]
  needs = ["Build Blog"]
  env = {
    MESSAGE = "https://lacourt.dev/ updated by Github Actions pipeline!"
  }
}

I created a new workflow directly from the Actions tab on Github. Things are even more easy than before, I choose a NodeJS starter workflow and adapted it to match my previous workflow.

Secrets are still accessible. Remember? they are defined in your Settings / Secrets section. You can then inject them in your Environment variables, f.ex.: ${{ secrets.API_KEY }}.

It seems the Cypress action does not work anymore so I just used the default one.

Let’s see if it’ll work…

The new file will be:

name: Node CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [8.x, 10.x, 12.x]

    steps:
    - uses: actions/checkout@v1
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - name: npm install, build, and test
      run: |
        npm ci
        npm run build --if-present
        npm test
      env:
        CI: true
    - name: Send Push Notification
      uses: techulus/push-github-action@master
      env:
        MESSAGE: "https://lacourt.dev/ updated by Github Actions pipeline!"
        API_KEY: ${{ secrets.API_KEY }}

I just pushed this on a Pull Request.

Results

Wow, nice, now there are checks in the Pull Request:

checks in the Pull Request
checks in the Pull Request

And you can see in a dedicated Checks tab:

Checks tab
Checks tab

Now, it is running…

Cypress tests running
Cypress tests running

And, luckily, everything went green! No more need for a dedicated Cypress action, it works out of the box!

Cypress tests green
Cypress tests green

Conclusion

This migration was quick!

In this post we’ve seen quickly how I migrated my old workflow to the new Github YAML format.

It was a short post because it was really easy to implement. I hope you found it interesting!

If you have any questions or feedback, or just want to say hi or thank you, my DMs are open on Twitter!