From 955f510f7b94d1f07956020c08dfc79e878bdfa8 Mon Sep 17 00:00:00 2001 From: Michel Roegl-Brunner Date: Thu, 13 Mar 2025 11:43:54 +0100 Subject: [PATCH] new Workflow --- .github/workflows/delete_new_script.yaml | 83 ++++++++++++++++++++++++ ct/snipeit.sh | 1 + install/snipeit-install.sh | 1 + json/snipeit.json | 0 4 files changed, 85 insertions(+) create mode 100644 .github/workflows/delete_new_script.yaml create mode 100644 ct/snipeit.sh create mode 100644 install/snipeit-install.sh create mode 100644 json/snipeit.json diff --git a/.github/workflows/delete_new_script.yaml b/.github/workflows/delete_new_script.yaml new file mode 100644 index 0000000..4ce5f89 --- /dev/null +++ b/.github/workflows/delete_new_script.yaml @@ -0,0 +1,83 @@ +name: Delete Files on Issue Close (With Existence Check) + +on: + issues: + types: [closed] + +jobs: + delete-files: + runs-on: ubuntu-latest + if: contains(github.event.issue.labels.*.name, 'Migration To ProxmoxVE') + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Issue Title + id: extract_title + run: echo "TITLE=$(echo '${{ github.event.issue.title }}' | sed 's/ /_/g')" >> $GITHUB_ENV + + - name: Check if Files Exist in community-scripts/ProxmoxVE + id: check_files + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + REPO="community-scripts/ProxmoxVE" + API_URL="https://api.github.com/repos/$REPO/contents" + + FILES=( + "ct/${TITLE}.sh" + "install/${TITLE}-install.sh" + "json/${TITLE}.json" + ) + + EXISTS=false + for FILE in "${FILES[@]}"; do + STATUS=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token $GH_TOKEN" "$API_URL/$FILE") + if [ "$STATUS" -eq 200 ]; then + EXISTS=true + echo "$FILE exists in $REPO" + else + echo "$FILE does NOT exist in $REPO" + fi + done + + if [ "$EXISTS" = false ]; then + echo "No matching files found in $REPO. Exiting..." + exit 0 + fi + + - name: Delete Files + run: | + rm -f ct/${TITLE}.sh + rm -f install/${TITLE}-install.sh + rm -f json/${TITLE}.json + + - name: Commit and Push Changes + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git add . + if git diff --staged --quiet; then + echo "No files to delete. Exiting..." + exit 0 + fi + git commit -m "Deleted files for issue: ${{ github.event.issue.title }}" + git push origin main + echo "COMMIT_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV + + - name: Comment on Issue + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const issue_number = context.payload.issue.number; + const commit_sha = process.env.COMMIT_SHA; + const message = `Files deleted and committed in [${commit_sha}](https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${commit_sha}).`; + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue_number, + body: message + }); diff --git a/ct/snipeit.sh b/ct/snipeit.sh new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/ct/snipeit.sh @@ -0,0 +1 @@ + diff --git a/install/snipeit-install.sh b/install/snipeit-install.sh new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/install/snipeit-install.sh @@ -0,0 +1 @@ + diff --git a/json/snipeit.json b/json/snipeit.json new file mode 100644 index 0000000..e69de29