Skip to content

Commit

Permalink
Add action of version update and add it to workflow
Browse files Browse the repository at this point in the history
Signed-off-by: jparisu <[email protected]>
  • Loading branch information
jparisu committed May 10, 2023
1 parent 4f2abfe commit 22a1e54
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 5 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/pr_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ on:

jobs:

dummy:
version-update:
runs-on: ubuntu-22.04
steps:
- name: Do nothing yet
shell: bash
run: |
echo "ToDo"
- name: Check wether the versions.md file have been updated
uses: eProsima/eProsima-CI/ubuntu/check_version_update@main
45 changes: 45 additions & 0 deletions ubuntu/check_version_update/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: check_version_update
description: Check if version file has been updated with the change in the repository

inputs:

version-file-path:
description: The path to the file to check for changes from repository base
required: true
default: versions.md

head-ref:
description: Git reference to compare file
required: false
default: ${GITHUB_HEAD_REF}

base-ref:
description: Git reference to compare against
required: false
default: ${GITHUB_BASE_REF}

runs:
using: composite
steps:

- name: Sync repository
uses: eProsima/eProsima-CI/external/checkout@main
with:
path: ${{ github.workspace }}

- name: Fetch all branches and tags
uses: eProsima/eProsima-CI/ubuntu/git_fetch_all@main
with:
workspace: ${{ github.workspace }}

- name: Get diff file of version file
id: git-diff
uses: eProsima/eProsima-CI/ubuntu/git_diff@main
with:
file-path: ${{ github.workspace }}/${{ inputs.version-file-path }}

- name: Check if file change
if: ${{ steps.git-diff.outputs.have-changes == 'false' }}
run: |
echo "Version file ${{ inputs.version-file-path }} has not been updated."
exit 1
61 changes: 61 additions & 0 deletions ubuntu/git_diff/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: git_diff
description: Check whether a file in a repository has changed and return diff file

inputs:

file-path:
description: The path to the file to check for changes
required: true

head-ref:
description: Git reference to compare file
required: false
default: ${GITHUB_HEAD_REF}

base-ref:
description: Git reference to compare against
required: false
default: ${GITHUB_BASE_REF}

diff-args:
description: Additional arguments to pass to the git diff command
required: false
default: ''

result-file:
description: Additional arguments to pass to the git diff command
required: false
default: '${{ github.workspace }}/git.diff'

outputs:

diff-file-result:
description: The path to the file containing the diff, if changes were detected

have-changes:
description: Whether there have been changes in such file

runs:
using: composite
steps:

- name: get_git_diff_files
shell: bash
run: |
echo "::group::Get git modifications of file ${{ inputs.file-path }}""
if git diff --name-only "${{ inputs.base-ref }}" "${{ inputs.head-ref }}" ${{ inputs.diff-args }} | grep -q "${{ inputs.file-path }}"; then
git diff "${{ inputs.base-ref }}" "${{ inputs.head-ref }}" ${{ inputs.diff-args }} "${{ inputs.file-path }}" > "${{ inputs.result-file }}"
echo "::set-output name=diff-file-result::$(cat ${{ inputs.result-file }})"
echo "::set-output name=have-changes::true"
else
echo "::set-output name=have-changes::false"
fi
echo "::endgroup::"

0 comments on commit 22a1e54

Please sign in to comment.