Validate #5234
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Validate | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
schedule: | |
- cron: "0 12 * * *" | |
concurrency: | |
cancel-in-progress: true | |
group: validate-${{ github.ref }} | |
jobs: | |
preflight: | |
if: ${{ github.repository == 'hacs/integration' }} | |
runs-on: ubuntu-latest | |
name: Preflight | |
steps: | |
- name: Validation preflight | |
env: | |
ACTOR: ${{ github.actor }} | |
EVENT_NAME: ${{ github.event_name }} | |
REF_NAME: ${{ github.ref_name }} | |
REF: ${{ github.ref }} | |
SHA: ${{ github.sha }} | |
run: | | |
echo "**Start:** $(date)" >> $GITHUB_STEP_SUMMARY | |
echo "**Actor:** $ACTOR" >> $GITHUB_STEP_SUMMARY | |
echo "**Event:** $EVENT_NAME" >> $GITHUB_STEP_SUMMARY | |
echo "**Ref name:** $REF_NAME" >> $GITHUB_STEP_SUMMARY | |
echo "**Ref:** $REF" >> $GITHUB_STEP_SUMMARY | |
echo "**SHA:** $SHA" >> $GITHUB_STEP_SUMMARY | |
validate-hassfest: | |
needs: | |
- "preflight" | |
runs-on: ubuntu-latest | |
name: With hassfest | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v4.2.0 | |
# Test files conflict with running hassfest | |
- name: Remove tests | |
run: rm -rf tests | |
- name: Hassfest validation | |
uses: "home-assistant/actions/hassfest@master" | |
validate-hacs: | |
needs: | |
- "preflight" | |
runs-on: ubuntu-latest | |
name: With HACS Action | |
steps: | |
- name: HACS validation | |
uses: hacs/action@main | |
with: | |
category: integration | |
validate-hacs-local: | |
if: ${{ github.event_name != 'schedule' }} | |
needs: | |
- "preflight" | |
runs-on: ubuntu-latest | |
name: Check ${{matrix.entry.category}} ${{matrix.entry.repository}} with HACS Action (local) | |
strategy: | |
matrix: | |
entry: | |
- repository: "hacs/integration" | |
category: "integration" | |
- repository: "piitaya/lovelace-mushroom" | |
category: "plugin" | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v4.2.0 | |
- name: Build Container | |
run: | | |
docker build . -t hacs/action:local -f action/Dockerfile | |
- name: Run Action | |
run: | | |
docker run --name hacs_action_local \ | |
--env INPUT_GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} \ | |
--env INPUT_REPOSITORY=${{matrix.entry.repository}} \ | |
--env INPUT_CATEGORY=${{matrix.entry.category}} \ | |
hacs/action:local | |
validata-hacs-data: | |
if: ${{ github.event_name != 'schedule' }} | |
needs: | |
- "preflight" | |
runs-on: ubuntu-latest | |
name: Check ${{matrix.entry.category}} ${{matrix.entry.repository}} with HACS data generation | |
strategy: | |
matrix: | |
entry: | |
- repository: "hacs/integration" | |
category: "integration" | |
- repository: "piitaya/lovelace-mushroom" | |
category: "plugin" | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v4.2.0 | |
- name: Set up Python | |
uses: actions/setup-python@v5.2.0 | |
with: | |
python-version: "3.12" | |
cache: 'pip' | |
cache-dependency-path: | | |
requirements_base.txt | |
requirements_generate_data.txt | |
- name: Install dependencies | |
run: | | |
scripts/install/frontend | |
scripts/install/pip_packages --requirement requirements_generate_data.txt | |
- name: Generate data | |
run: | | |
python3 -m scripts.data.generate_category_data \ | |
${{ matrix.entry.category }} \ | |
${{ matrix.entry.repository }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Generate diff | |
run: | | |
diff -U 8 outputdata/diff/${{ matrix.entry.category }}_before.json outputdata/diff/${{ matrix.entry.category }}_after.json > outputdata/diff/${{ matrix.entry.category }}.diff || true | |
cat outputdata/diff/${{ matrix.entry.category }}.diff | |
- name: Upload diff | |
uses: actions/github-script@v7.0.1 | |
env: | |
CATEGORY: ${{ matrix.entry.category }} | |
with: | |
script: | | |
const fs = require('fs'); | |
const diffContents = fs.readFileSync(`outputdata/diff/${process.env.CATEGORY}.diff`); | |
core.summary.addDetails(`${process.env.CATEGORY}.diff contents`, `\n\n\`\`\`diff\n${diffContents}\`\`\`\n\n`) | |
core.summary.write() | |
- name: Validate output with JQ | |
run: | | |
jq -c . outputdata/${{ matrix.entry.category }}/data.json | |
jq -c . outputdata/${{ matrix.entry.category }}/repositories.json | |
- name: Validate output with schema | |
run: | | |
python3 -m scripts.data.validate_category_data ${{ matrix.entry.category }} outputdata/${{ matrix.entry.category }}/data.json | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4.4.0 | |
with: | |
name: "${{ matrix.entry.category }}_${{ strategy.job-index }}" | |
path: | | |
outputdata/summary.json | |
outputdata/${{ matrix.entry.category }} | |
outputdata/diff | |
if-no-files-found: error | |
retention-days: 3 | |
notify_on_failure: | |
runs-on: ubuntu-latest | |
name: Trigger Discord notification when jobs fail | |
needs: ["preflight","validate-hassfest", "validate-hacs"] | |
steps: | |
- name: Send notification | |
if: ${{ always() && contains(join(needs.*.result, ','), 'failure') && github.event_name == 'schedule' }} | |
run: | | |
curl \ | |
-H "Content-Type: application/json" \ | |
-d '{"username": "GitHub action failure", "content": "[Scheduled action failed!](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}})"}' \ | |
${{ secrets.DISCORD_WEBHOOK_ACTION_FAILURE }} |