From ee48b716d8077b7122469048e00bceb0835d932e Mon Sep 17 00:00:00 2001 From: sirmrak Date: Wed, 22 Jul 2026 14:22:12 +0300 Subject: [PATCH] Add .gitea/workflows/init_integration.yml --- .gitea/workflows/init_integration.yml | 88 +++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 .gitea/workflows/init_integration.yml diff --git a/.gitea/workflows/init_integration.yml b/.gitea/workflows/init_integration.yml new file mode 100644 index 0000000..84f0cf5 --- /dev/null +++ b/.gitea/workflows/init_integration.yml @@ -0,0 +1,88 @@ +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 \ No newline at end of file