diff --git a/.github/workflows/convert.yml b/.github/workflows/convert.yml index fde38ab..dc0497c 100644 --- a/.github/workflows/convert.yml +++ b/.github/workflows/convert.yml @@ -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 "github-actions@github.com" + git add . + git commit -m "Automated commit by GitHub Action" + git push + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}