Skip to content

Commit

Permalink
ci: refactor conversion workflow
Browse files Browse the repository at this point in the history
Using github.event.pull_request and the paths-filter, we can simplify this

- only run action if config changed
- change workflow to only run job if no draft & open
- rename to synchronization since it's no conversion
- no manual triggering necessary

fixes GIScience#1685

Co-authored-by: Amandus <[email protected]>
  • Loading branch information
2 people authored and selimguvenc committed Apr 25, 2024
1 parent 8dbec06 commit 1ba3dcc
Showing 1 changed file with 8 additions and 35 deletions.
43 changes: 8 additions & 35 deletions .github/workflows/config-conversion-automation.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,29 @@
name: Automatic conversion of application.yml to ors-config.yml
name: Automatic synchronization of application.yml to ors-config.yml
on:
pull_request:
branches:
- main
- releases/**
types: [ edited, opened, ready_for_review, review_requested, reopened, synchronize ]
workflow_dispatch:

types: [ opened, ready_for_review, reopened, synchronize ]
paths:
- 'ors-api/src/main/resources/application.yml'

jobs:
detect_config_change:
name: Detect and commit config changes
sync_config:
name: Synchronize changes in application.yml to ors-config.yml
runs-on: ubuntu-latest
permissions:
contents: write
if: (! github.event.pull_request.draft) && github.event.pull_request.state == 'open'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Check PR state is ready_for_review
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
pr_state=$(gh pr view --json state --jq .state)
pr_is_draft=$(gh pr view --json isDraft --jq .isDraft)
echo "pr_state=$pr_state" >> $GITHUB_ENV
echo "pr_is_draft=$pr_is_draft" >> $GITHUB_ENV
else
echo "This action is only intended to be run on pull requests."
exit 1
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Convert application.yml to ors-config.yml
run: |
.github/utils/config_conversion.sh ors-api/src/main/resources/application.yml ors-config.yml
- name: Check with git if ors-api/ors-config.yml has changed
id: git-check
if: env.pr_state == 'OPEN' && env.pr_is_draft == 'false'
run: |
# Don't fail on exit code 1 (diff found)
set +e
git diff --exit-code --name-only ors-api/ors-config.yml
exit_value=$?
echo Found exit code $exit_value
# Write out the exit code using environment file
if [ $exit_value == 1 ]; then
echo "config_has_changed=true" >> $GITHUB_ENV
else
echo "Config hasn't changed. Skipping commit."
fi
- uses: MichaelsJP/git-auto-commit-action@v5
if: env.pr_state == 'OPEN' && env.pr_is_draft == 'false' && env.config_has_changed == 'true'
with:
commit_message: 'chore(config): automatic conversion of application.yml to ors-config.yml'

0 comments on commit 1ba3dcc

Please sign in to comment.