Files
StrikePackageGPT/.github/workflows/unpack-zip.yml

120 lines
4.2 KiB
YAML

name: Unpack files.zip (create branch + PR)
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch containing files.zip'
required: true
default: 'C2-integration'
permissions:
contents: write
pull-requests: write
jobs:
unpack-and-pr:
runs-on: ubuntu-latest
steps:
# ---------------------------------------------------------
# 0. Checkout the target branch ONLY — prevents recursion
# ---------------------------------------------------------
- name: Checkout target branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}
fetch-depth: 0
persist-credentials: true
- name: Install tools
run: |
sudo apt-get update -y
sudo apt-get install -y unzip rsync jq
# ---------------------------------------------------------
# 1. Verify files.zip exists in branch root
# ---------------------------------------------------------
- name: Check for files.zip
run: |
if [ ! -f "files.zip" ]; then
echo "::error ::files.zip not found in root of branch ${{ github.event.inputs.branch }}"
exit 1
fi
echo "Found files.zip:"
ls -lh files.zip
# ---------------------------------------------------------
# 2. Unzip files into extracted/
# ---------------------------------------------------------
- name: Extract zip
run: |
rm -rf extracted
mkdir extracted
unzip -o files.zip -d extracted
echo "Extracted files sample:"
find extracted -type f | sed -n '1,50p'
# ---------------------------------------------------------
# 3. Copy extracted files into root of repo
# ---------------------------------------------------------
- name: Copy extracted contents
run: |
rsync -a extracted/ . --exclude='.git'
# ---------------------------------------------------------
# 4. Detect changes and create commit branch
# ---------------------------------------------------------
- name: Commit changes if any
id: gitops
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if git status --porcelain | grep -q . ; then
BRANCH="unpacked-${{ github.event.inputs.branch }}-$(date +%s)"
git checkout -b "$BRANCH"
git add -A
git commit -m "Unpacked files.zip automatically"
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
else
echo "nochanges=true" >> $GITHUB_OUTPUT
fi
# ---------------------------------------------------------
# 5. Push branch only if changes exist
# ---------------------------------------------------------
- name: Push branch
if: steps.gitops.outputs.nochanges != 'true'
run: |
git push --set-upstream origin "${{ steps.gitops.outputs.branch }}"
# ---------------------------------------------------------
# 6. Open PR only if changes exist
# ---------------------------------------------------------
- name: Open Pull Request
if: steps.gitops.outputs.nochanges != 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "Automated unpack of files.zip into ${{ github.event.inputs.branch }}"
body: |
This PR was automatically generated.
**Action:** Unpacked `files.zip` from branch `${{ github.event.inputs.branch }}`.
**Branch:** `${{ steps.gitops.outputs.branch }}`
base: ${{ github.event.inputs.branch }}
head: ${{ steps.gitops.outputs.branch }}
draft: false
# ---------------------------------------------------------
# 7. Final log
# ---------------------------------------------------------
- name: Done
run: |
if [ "${{ steps.gitops.outputs.nochanges }}" = "true" ]; then
echo "No changes detected. Nothing to commit."
else
echo "PR created successfully."
fi