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

1

7

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'           
Alvarado answered 7/5, 2021 at 8:39 Comment(2)
It seems that the version file is created by javascript code which is not posted. It is unclear if the question is about the content of the v2 file.Humanize
The version file is created manually called release.yml . it contains the version number and the corresponding body given above. The ideal process would be that on file change the github action would detect the change in this file and perform CRUD sort of operation that is if there is a newer version added to the file new release note would be created. Ill update the so far github action code aswell for better understanding.Alvarado
G
1

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.

Gerge answered 21/5, 2021 at 2:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.