Skip to content

Commit

Permalink
Merge pull request #4 from UW-GAC/feature/internal-refs
Browse files Browse the repository at this point in the history
Use internal references for calling sub-actions
  • Loading branch information
amstilp authored May 28, 2024
2 parents 64fbb0b + dccb80e commit a4dd616
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 16 deletions.
11 changes: 9 additions & 2 deletions check-requirements-files/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,23 @@ runs:
using: "composite"
steps:

- name: Symlink current action repo
env:
action_path: ${{ github.action_path }}
run: |
if [[ ! -d .github/.action_repo ]]; then ln -fs ${{ env.action_path }}/.. .github/.action_repo; fi
shell: bash

- name: Run pip-compile
id: run-pip-compile
uses: UW-GAC/pip-tools-actions/run-pip-compile@main
uses: ./.github/.action_repo/run-pip-compile
with:
requirements_files: ${{ inputs.requirements_files }}
pip-tools-version: ${{ inputs.pip-tools-version }}
pip-compile-args: ${{ inputs.pip_compile_args }}

- name: "Fail if there are changes to requirements files"
if: steps.run-pip-compile.outputs.FILES_CHANGED == '1'
if: steps.run-pip-compile.outputs.CHANGES_DETECTED == '1'
run: |
echo "Changes to requirements files detected"
exit 1
Expand Down
43 changes: 33 additions & 10 deletions run-pip-compile/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,26 @@ inputs:
required: false
default: ""
outputs:
files_changed:
CHANGES_DETECTED:
description: "A flag indicating whether the requirements files have changed."
value: ${{ steps.pip-compile-changes.outputs.FILES_CHANGED }}
value: ${{ steps.detect-changes.outputs.CHANGES_DETECTED }}
OUTPUT_FILES:
description: "The names of the output files generated by pip-compile."
value: ${{ steps.get-output-files.outputs.OUTPUT_FILES }}

runs:
using: "composite"
steps:

- name: Symlink current action repo
env:
action_path: ${{ github.action_path }}
run: |
if [[ ! -d .github/.action_repo ]]; then ln -fs ${{ env.action_path }}/.. .github/.action_repo; fi
shell: bash

- name: Set up pip-tools
uses: UW-GAC/pip-tools-actions/setup-pip-tools@main
uses: ./.github/.action_repo/setup-pip-tools
with:
pip-tools-version: ${{ inputs.pip-tools-version }}

Expand All @@ -48,24 +58,37 @@ runs:
INPUT_REQUIREMENTS_FILES: ${{ inputs.requirements_files }}
INPUTS_PIP_COMPILE_ARGS: ${{ inputs.pip_compile_args }}

- name: Set output
id: pip-compile-changes
- name: Get names of output files from pip-compile
id: get-output-files
run: |
output_files=()
for file in $INPUT_REQUIREMENTS_FILES
do
output_files+=("${file%.in}.txt")
done
echo "OUTPUT_FILES=${output_files[@]}" >> $GITHUB_OUTPUT
shell: bash
env:
INPUT_REQUIREMENTS_FILES: ${{ inputs.requirements_files }}

- name: Detect if any changes were made to requirements files
id: detect-changes
run: |
function check() {
if [[ -z "$(git status --porcelain $STATUS_ARGS $PATHSPEC)" ]];
if [[ -z "$(git status --porcelain ${{ steps.get-output-files.outputs.OUTPUT_FILES}})" ]];
then
echo "0"
else
echo "1"
fi
}
echo "FILES_CHANGED=$(check)" >> $GITHUB_OUTPUT
echo "CHANGES_DETECTED=$(check)" >> $GITHUB_OUTPUT
shell: bash

- name: List changes
if: steps.pip-compile-changes.outputs.FILES_CHANGED
if: steps.detect-changes.outputs.CHANGES_DETECTED
run: |
git status
git diff
git status ${{ steps.get-output-files.outputs.OUTPUT_FILES}}
git diff ${{ steps.get-output-files.outputs.OUTPUT_FILES}}
shell: bash
26 changes: 22 additions & 4 deletions update-requirements-files/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,33 @@ runs:
using: "composite"
steps:

- name: Symlink current action repo
env:
action_path: ${{ github.action_path }}
run: |
if [[ ! -d .github/.action_repo ]]; then ln -fs ${{ env.action_path }}/.. .github/.action_repo; fi
shell: bash

- name: Run pip-compile
id: run-pip-compile
uses: UW-GAC/pip-tools-actions/run-pip-compile@main
uses: ./.github/.action_repo/run-pip-compile
with:
requirements_files: ${{ inputs.requirements_files }}
pip-tools-version: ${{ inputs.pip-tools-version }}
pip-compile-args: ${{ inputs.pip_compile_args }}

- name: Prep output files for pull request
id: prep-output-files
run: |
# Replace spaces with commas
output_files="${{ steps.run-pip-compile.outputs.OUTPUT_FILES }}"
output_files_pr="${output_files// /","}"
echo $output_files_pr
echo "OUTPUT_FILES_PR=${output_files_pr}" >> $GITHUB_OUTPUT
shell: bash

- name: Create Pull Request
if: steps.run-pip-compile.outputs.FILES_CHANGED == '1'
if: steps.run-pip-compile.outputs.CHANGES_DETECTED == '1'
id: create-pull-request
uses: peter-evans/create-pull-request@v6
with:
Expand All @@ -65,9 +82,10 @@ runs:
labels: ${{ inputs.pr-labels }}
# Create a new branch for each pull request.
branch: pip-tools/update-requirements-files/${{ inputs.pr-branch-suffix }}
add-paths: ${{ steps.prep-output-files.outputs.OUTPUT_FILES_PR }}

- name: "Fail if there are changes to requirements files"
if: steps.run-pip-compile.outputs.FILES_CHANGED == '1'
- name: Fail if there are changes to requirements files
if: steps.run-pip-compile.outputs.CHANGES_DETECTED == '1'
run: |
echo "Changes to requirements files detected"
echo "Please merge pull request to resolve:"
Expand Down

0 comments on commit a4dd616

Please sign in to comment.