GithubHelp home page GithubHelp logo

jorgebg / stateful-action Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 2.0 8 KB

An utility for managing the state of your application on a reserved branch.

License: MIT License

JavaScript 61.69% Shell 31.85% Makefile 6.46%

stateful-action's Introduction

💾 Stateful Action

This action is an utility for managing the state of your application on a branch reserved for this purpose.

How it works

It wraps the run like this:

  1. state branch is checked out as a worktree under a folder named .state (which must be ignored by .gitignore). Please check scripts/main.sh.
  2. Your application writes its state into the .state folder.
  3. Changes in state branch are commited and pushed to origin. Please check scripts/post.sh:
    • Changes are commited and pushed.
    • Old commits on state branch are squashed and force-pushed.
    • .state worktree is removed.

Your application might also commit or push changes at step 2 if needed.

Requirements

  • The repository must reserve a branch for keeping the state. By default its name is state. It can be set by the branch input.
  • A folder with the same name as the state branch prefixed by a dot must be ignored in .gitignore (example). As the default branch is state, the folder ignored by default would be .state.
  • Repository must be checked out first (actions/checkout@v2).

Usage

Example workflow

name: Example workflow
on:
  push:
    branches: [master]
jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - uses: jorgebg/[email protected]
    - name: Test Run
      run: echo $(date)\n >> .state/data.txt

Please take a look at the example workflow running on this repository.

Inputs

  • branch: the name of the branch that will store the state. Default: state.

  • backup: number of last commits to keep as a backup. Default: 100.

  • git_author_name: author name used for the commits. Default: Stateful Action Bot.

  • git_author_email: author email used for the commits. Default: [email protected].

Real-life examples

Testing

Simple testing

node main.js && echo $(date)\n >> .state/data.txt
node post.js

Testing with act

The action can be tested locally with act. It requires git and sed, so use the image node:12.6-buster instead of the slim version:

act -P ubuntu-latest=node:12.6-buster

You'll also need to setup GitHub credentials.

Known issues

Here is a workaround I'm using for nektos/act#185:

rm -rf action
mkdir action
cp -R action.yml *.js scripts action
sed -i -E 's/uses: .\/$/uses: .\/action/g' .github/workflows/example.yml

It copies the local action into action folder.

stateful-action's People

Contributors

jorgebg avatar

Stargazers

Vince Cima avatar Rafał Gałka avatar Roman avatar Tobias Wittwer avatar Michaël Rivet avatar Ian Sutherland avatar Navid avatar  avatar

Watchers

 avatar

stateful-action's Issues

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.