Code Monkey home page Code Monkey logo

file-changes-action's Introduction

file-changes-action

This action will take the information from the Push/Pull Request and output some variables and write files that will let you know what was changed, removed, or added.

Use Cases

I have a process where I have AWS Cloudformation templates stored in one directory that might be named PRODUCT-ROLE, and mappings for these templates that span the PRODUCT. For example mappings/wordpress.mappings.yml, templates/wordpress-database.yml, templates/wordpress-webserver.yml, and some of the templates might use different Lambda functions defined in for example functions/wordpress-webserver/.

In the example below we have a workflow that on push to the develop branch we can perform some actions based on the files. In my use case I look for changes on the develop branch of this repository for every push that happens. When a push happens and a change is made to any of the paths below the workflow will trigger. With this action you are able to know exactly which files changed so that you can make decisions later in your CI/CD.

In this case, if a templates/*.yml file is changed, then we want to update the Cloudformation stack. We can also write specifics for related templates. For example, if templates/wordpress-database.yml changes then we want to deploy templates/wordpress-webserver.yml as well after.

Another case is if the mappings/wordpress.mappings.yml changes, we want to deploy all template/wordpress-*.yml files.

How to Use

In order to make those decisions we need to know what files have changed and that is where this action comes in. In the example below we are checking out our repository code, and then running the trilom/file-changes-action@v1 action. The only thing you need to provide is a GITHUB_TOKEN so that Octokit can make it's API calls.

If a PR is made then it will look at all of the files included in the PR. If a push is made then it will compare commits from the SHA github.context.payload.before to the SHA github.context.payload.after of the push.

After gathering this information it will output the files in 2 ways.

  • As an output variable, you can use this variable by using steps.file_changes.outputs.files_modified, steps.file_changes.outputs.files_added, steps.file_changes.outputs.files_deleted.

  • As a file on the container stored at $HOME/files.json, $HOME/files_modified.json, $HOME/files_added.json, $HOME/files_deleted.json. Example:

["cloudformation/mappings/wordpress.mappings.yml","cloudformation/templates/wordpress-database.yml"]

Examples

name: push-develop

on:
  push:
    branches:
      - develop
    paths:
      - 'cloudformation/templates/*.yml'
      - 'cloudformation/mappings/*.yml'
      - 'functions/*'
  
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - id: file_changes
        uses: trilom/file-changes-action@v1
        with:
          githubToken: ${{ secrets.GITHUB_TOKEN }}
      - name: test
        run: |
          ls $HOME
          cat $HOME/files.json
          cat $HOME/files_modified.json
          cat $HOME/files_added.json
          cat $HOME/files_deleted.json
          echo '${{ steps.file_changes.outputs.files_modified}}'
          echo '${{ steps.file_changes.outputs.files_added}}'
          echo '${{ steps.file_changes.outputs.files_deleted}}'

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.