Template
88 lines
2.9 KiB
YAML
88 lines
2.9 KiB
YAML
name: Initialize Integration
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- master
|
|
|
|
jobs:
|
|
init:
|
|
name: Initialize Integration
|
|
runs-on: ubuntu-latest
|
|
if: github.run_number == 1
|
|
permissions:
|
|
contents: write
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
token: ${{ secrets.PAT_TOKEN }}
|
|
|
|
- name: Get repository name
|
|
id: repo_name
|
|
run: |
|
|
REPO_NAME=$(basename $GITHUB_REPOSITORY)
|
|
echo "repo_name=$REPO_NAME" >> $GITHUB_OUTPUT
|
|
echo "Repository name: $REPO_NAME"
|
|
|
|
- name: Rename integration folder
|
|
run: |
|
|
CURRENT_FOLDER=$(find custom_components -mindepth 1 -maxdepth 1 -type d | head -1)
|
|
|
|
if [ -z "$CURRENT_FOLDER" ]; then
|
|
echo "Error: No integration folder found in custom_components/"
|
|
exit 1
|
|
fi
|
|
|
|
mv "$CURRENT_FOLDER" "custom_components/${{ steps.repo_name.outputs.repo_name }}"
|
|
echo "Renamed $CURRENT_FOLDER to custom_components/${{ steps.repo_name.outputs.repo_name }}"
|
|
|
|
- name: Update manifest.json
|
|
run: |
|
|
MANIFEST="custom_components/${{ steps.repo_name.outputs.repo_name }}/manifest.json"
|
|
|
|
python3 << EOF
|
|
import json
|
|
|
|
with open('$MANIFEST', 'r') as f:
|
|
manifest = json.load(f)
|
|
|
|
manifest['domain'] = '${{ steps.repo_name.outputs.repo_name }}'
|
|
manifest['name'] = '${{ steps.repo_name.outputs.repo_name }}'.replace('_', ' ').title()
|
|
|
|
with open('$MANIFEST', 'w') as f:
|
|
json.dump(manifest, f, indent=2)
|
|
f.write('\n')
|
|
|
|
print(f"Updated manifest.json: domain={manifest['domain']}, name={manifest['name']}")
|
|
EOF
|
|
|
|
- name: Update const.py
|
|
run: |
|
|
CONST_FILE="custom_components/${{ steps.repo_name.outputs.repo_name }}/const.py"
|
|
|
|
if [ -f "$CONST_FILE" ]; then
|
|
sed -i "s/DOMAIN = \".*\"/DOMAIN = \"${{ steps.repo_name.outputs.repo_name }}\"/g" "$CONST_FILE"
|
|
echo "Updated DOMAIN in const.py"
|
|
fi
|
|
|
|
- name: Commit changes
|
|
run: |
|
|
git config --local user.email "actions@gitea.local"
|
|
git config --local user.name "Gitea Actions Bot"
|
|
|
|
git add -A
|
|
git diff --staged --quiet || git commit -m "chore: initialize integration with repository name"
|
|
git push origin main
|
|
|
|
- name: Summary
|
|
run: |
|
|
echo "## Integration Initialized" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Repository:** ${{ github.repository }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "**Integration name:** ${{ steps.repo_name.outputs.repo_name }}" >> $GITHUB_STEP_SUMMARY
|
|
echo "" >> $GITHUB_STEP_SUMMARY
|
|
echo "All files have been updated automatically." >> $GITHUB_STEP_SUMMARY |