GithubHelp home page GithubHelp logo

tfonfara / last-successful-commit-action Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nrwl/last-successful-commit-action

0.0 0.0 0.0 947 KB

GitHub action for identifying the last successful commit for a given workflow and branch.

JavaScript 100.00%

last-successful-commit-action's Introduction

"Last successful commit" action

This action returns the commit hash when a given workflow was last successful.

This is especially useful when we have a workflow where we need to know what changed in on a given branch between two commits, so we can run some tasks on those changes.

Scroll down to the background section below for more info around why this would be useful.

Inputs

branch

Required Branch to get last successful commit from (eg. ${{ github.ref_name }}).

Default: main

github_token

Required Your GitHub access token (see usage below).

workflow_id

Required ID or filename of the workflow (e.g. ${{ github.workflow }}). See docs.

Outputs

commit_sha

SHA of the last successful commit.

Example usage

name: Deploy Website

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    name: Deploying affected apps
    steps:
      - uses: actions/checkout@v1
      - uses: bahmutov/[email protected]
      - uses: tfonfara/last-successful-commit-action@v1
        id: last_successful_commit
        with:
          branch: master
          workflow_id: deploy.yml
          github_token: ${{ secrets.GITHUB_TOKEN }}
      - run: npm run nx affected -- --target=build --base=${{ steps.last_successful_commit.outputs.commit_sha }} --parallel --configuration=production

Background

When using a tool like Nx, for example, it has a feature where you give it 2 commits, and it calculates which projects in your repository changed between those 2 commits. We can then run a set of tasks (like building or linting) only on those affected projects.

This makes it easy to set-up a CI system that scales really well with the continous growth of your repository, as you add more and more projects.

Problem

On a CI system that runs on submitted PRs, it's easy to determine what commits to include in the affected calculation: everything between latest origin/master and HEAD-commit-of-my-PRs-branch. As that includes all the changes our PR will introduce to master.

But what if we want to set up a continuous deployment system that, as changes get pushed to master, it builds and deploys only the affected projects?

What are the FROM and TO commits in that case?

They can't be just HEAD and HEAD~1 - as we might push a bunch of commits into master. We want to include ALL those commits when determining affected.

There's also the issue of failures - if a few deployments fail one after another, that means that we're accumulating a list of affected projects that are not getting deployed. Anytime we retry the deployment, we want to include every commit since the last time we deployed successfully. That way we ensure we don't accidentally skip deploying a project that has changed.

Here's an attempt at demonstrating the problem above:

Failed deployments

last-successful-commit-action's People

Contributors

tfonfara avatar rarmatei avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.