Skip to content

Commit

Permalink
Calls validate workflow, commits new JSON files only if valid
Browse files Browse the repository at this point in the history
  • Loading branch information
radishmouse committed Jul 12, 2024
1 parent 040182f commit ee5ee6a
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions .github/workflows/convert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,66 @@ on:
- "yaml/**.yaml"

jobs:
convert:
convert-yaml:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run python script
run: |
python convert-yaml.py yaml json
if [ -d "yaml" ] && [ "$(ls -A yaml/*.yaml 2>/dev/null)" ]; then
python convert-yaml.py yaml json
else
echo "No YAML files to process."
fi
- name: Upload JSON artifacts for validation
uses: actions/upload-artifact@v4
with:
name: json-files
path: json/*.json

validate-json:
needs: convert-yaml
uses: ./.github/workflows/validate.yml
with:
should_download: true

commit-json:
runs-on: ubuntu-latest
needs: validate-json

steps:
- uses: actions/checkout@v4

- name: Check for validation success and file changes
run: |
if [ "${{ needs.validate-json.outputs.is_valid }}" != "true" ]; then
echo "JSON is not valid. Skipping commit."
echo "NO_COMMIT=true" >> $GITHUB_ENV
elif git diff --quiet; then
echo "No changes to commit"
echo "NO_COMMIT=true" >> $GITHUB_ENV
fi
- name: Commit changes
if: ${{ env.NO_COMMIT != 'true' }}
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git add .
git commit -m "Automated commit by GitHub Action"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit ee5ee6a

Please sign in to comment.