Skip to content

talentpair/last-green-commit-action

Repository files navigation

typescript-action status

last-green-commit-action: Get the last green commit in your git branch

There are times when it is handy to know what commit was the last one to pass all CI checks. We use this to do a git diff since the last green commit and decide which portions of our monorepos need to be tested or deployed.

Using this action

You'll have to bring your own script to do anything like that with your own repo, but getting the last green commit is the first step!

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: talentpair/last-green-commit-action@master
        id: last-green-commit
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
      # In our case, this is a node script that reads the ENV variable and does the git diffing analysis
      - run: yarn test:ci
        env:
          LAST_GREEN_COMMIT: ${{ steps.last-green-commit.outputs.result }}

Contributing

First, you'll need to have a reasonably modern version of node handy. This won't work with versions older than 9, for instance.

Install the dependencies

$ yarn install

Build the typescript and package it for distribution

$ yarn build && yarn package

Run the tests ✔️

$ yarn test

 PASS  ./index.test.js
  ✓ throws invalid number (3ms)
  ✓ wait 500 ms (504ms)
  ✓ test runs (95ms)

...

Change action.yml

The action.yml contains defines the inputs and output for your action.

Update the action.yml with your name, description, inputs and outputs for your action.

See the documentation

Change the Code

Most toolkit and CI/CD operations involve async operations so the action is run in an async function.

import * as core from '@actions/core';
...

async function run() {
  try {
      ...
  }
  catch (error) {
    core.setFailed(error.message);
  }
}

run()

See the toolkit documentation for the various packages.

Publish to a distribution branch

Actions are run from GitHub repos so we will checkin the packed dist folder.

Then run ncc and push the results:

$ yarn package
$ git add dist
$ git commit -a -m "prod dependencies"
$ git push origin releases/v1

Note: We recommend using the --license option for ncc, which will create a license file for all of the production node modules used in your project.

Your action is now published! 🚀

See the versioning documentation

Validate

You can now validate the action by referencing ./ in a workflow in your repo (see test.yml)

uses: ./
with:
  milliseconds: 1000

See the actions tab for runs of this action! 🚀

Usage:

After testing you can create a v1 tag to reference the stable and latest V1 action

About

Get the last green commit for your repo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •