GithubHelp home page GithubHelp logo

isabella232 / actions-mutex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zendesk/actions-mutex

0.0 0.0 0.0 1.64 MB

A GitHub Action for exclusive control

License: MIT License

Shell 9.89% JavaScript 1.78% TypeScript 88.33%

actions-mutex's Introduction

actions-mutex

A GitHub Action for exclusive control.

FEATURE

  • avoid running multiple jobs concurrently across workflows

OFFICIAL CONCURRENCY SUPPORT ON GITHUB ACTIONS

The action is no longer maintained.

On April 19, 2021, GitHub launched support for limiting concurrency in the workflow files. Please consider to use this feature.

Using this feature, the example in the SYNOPSIS section may be:

on:
  push:
    branches:
      - main

# The workflow level concurrency
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#concurrency
concurrency: deploy

jobs:
  build:

    # The job level concurrency
    # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idconcurrency
    concurrency: deploy

    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: ': some jobs that can not run concurrently'

Please read the latest document of Workflow syntax for GitHub Actions.

SYNOPSIS

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - uses: shogo82148/actions-mutex@v1
        with:
          key: deploy

      - run: ': some jobs that can not run concurrently'

INPUTS

key

The name of the critical section. The default is "lock".

token

A GitHub Token. It must have a write access to the repository. The default is "${{ github.token }}"

repository

A repository for locking. The default is the repository that the workflow runs on.

prefix

Prefix of branch names for locking. The default is "actions-mutex-lock/"

HOW THE ACTION WORKS

As you known, Git rejects non-fast-forward updates. The action uses it for locking.

The action tries to push a commit that contains a random string. If the pushing succeeds, it means that no concurrent jobs run.

$ echo "$RANDOM" > lock.txt
$ git add lock.txt
$ git commit -m 'add lock files'
$ git push origin HEAD:actions-mutex-lock/lock
To https://github.com/shogo82148/actions-mutex
 * [new branch]      HEAD -> actions-mutex-lock/lock

If the pushing fails, it means that a concurrent job is now running. The action will retry to push after some wait.

$ echo "$RANDOM" > lock.txt
$ git add lock.txt
$ git commit -m 'add lock files'
$ git push origin HEAD:actions-mutex-lock/lock
To https://github.com/shogo82148/actions-mutex
 ! [rejected]        HEAD -> actions-mutex-lock/lock (fetch first)
error: failed to push some refs to 'https://github.com/shogo82148/actions-mutex'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

actions-mutex's People

Contributors

shogo82148 avatar dependabot[bot] 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.