get git changes against version number in customised release.yml file

667 Views Asked by At

My objective is to create a GitHub action that, when the release.yml file changes, would either update an existing release or create a new release after checking if that release version is new checking against the previous commit. Ultimately would like to add this to other projects where I would like to add actions and release.yml.

The current issue I am having is difficulty in wrapping my head around how to go about is detecting changes in the release.yml file against the version.

For the very basic use case of adding a new release a simple approach of creating action.yml and adding

version_1_0: # id of input
description: '1.0'
required: true
default: 'The most important changes are downgrading the artifact to java7 (from 8) and switching to gmavenplus plugin to compile groovy.
      Besides that, there is a lot of restructuring inside of the pom.xml file

      # Misc

      * Polishing (f2ec0bb, 9e2ae89 and 8654493)

      _Reviewed by_: @user' 

and later in index.js file

const version = core.getInput('version_1_0');
core.setOutput("ver", version);

gives the output which later in the GitHub actions file can be fetched and cleaned and later forwarded to the release step to be used to create the release

  push:
    paths:
      - release.yml
    branches:
      - file_change_trigger
jobs:
  hello_world_job:
    runs-on: ubuntu-latest
    name: release notes
    outputs:
      output1: ${{ steps.step1.outputs.test }}
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - run: 
            description=${{ steps.hello.outputs.ver }}
            echo $description
            description="${description//'%'/'%25'}" 
            description="${description//$'\n'/'%0A'}"
            description="${description//$'\r'/'%0D'}" 
            echo $description
            echo "::set-output name=test::$description"
  
  release_note:
        name: Create Release
        runs-on: ubuntu-latest
        needs: hello_world_job
        steps:
          - name: Checkout code
            uses: actions/checkout@v2
             # Use the output from the `hello` step
          - name: Get the output time
            run: echo "${{needs.hello_world_job.outputs.output1}}"
          - name: Create Release
            id: create_release
            uses: actions/create-release@v1
            env:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
            with:
              tag_name: ${{ github.ref }}
              release_name: Release ${{ github.ref }}
              body: |
                ${{needs.hello_world_job.outputs.output1}}
              draft: false
              prerelease: false  

Unfortunately, this approach proved insufficient when I attempt for a file-based trigger based on diffs.

sample release.yml

    v1.0:
     body:
          'The most important changes are downgrading the artifact to java7 (from 8) and switching to gmavenplus plugin to compile groovy.
          Besides that, there is a lot of restructuring inside of the pom.xml file

          # Misc

          * Polishing (f2ec0bb, 9e2ae89 and 8654493)

          _Reviewed by_: @user'
    v2.0:
     body:
          'The most important changes are downgrading the artifact to java7 (from 8) and switching to gmavenplus plugin to compile groovy.
          

          # Misc

          * Polishing (f2ec0bb, 9e2ae89 and 8654493)

          _Reviewed by_: @user'           
1

There are 1 best solutions below

0
asyncninja On

Instead of tracking changes in a release.yml file, why don't you use Github releases to keep track and trigger Github actions. https://docs.github.com/en/actions/reference/events-that-trigger-workflows#release

on:
  release:
    types: [published]

Here you get the option of properly maintaining versions and changelog which is accessible in the action also if need be.