name: Update 7-Zip Binaries on: schedule: - cron: '0 0 * * *' # Daily at midnight UTC workflow_dispatch: # Allow manual trigger jobs: update: runs-on: ubuntu-latest # Adjust to your runner OS steps: - name: Checkout repository uses: actions/checkout@v4 with: token: ${{ secrets.GITEA_TOKEN }} - name: Set up environment run: | # Install dependencies (e.g., curl, git) sudo apt-get update && sudo apt-get install -y curl git jq # Ensure 7zz is available for extraction (download latest if not in PATH) if ! command -v 7zz &> /dev/null; then curl -L https://github.com/ip7z/7zip/releases/latest/download/7zz -o /tmp/7zz chmod +x /tmp/7zz export PATH="/tmp:$PATH" fi - name: Fetch latest release id: release run: | RELEASE_INFO=$(curl -s -H "Accept: application/vnd.github+json" \ -H "Authorization: token ${{ secrets.GH_TOKEN || '' }}" \ https://api.github.com/repos/ip7z/7zip/releases/latest) VERSION=$(echo "$RELEASE_INFO" | jq -r .tag_name | sed 's/v//') # e.g., 25.01 ASSETS=$(echo "$RELEASE_INFO" | jq -r '.assets[] | "\(.name)|\(.browser_download_url)|\(.size)"') echo "version=$VERSION" >> $GITHUB_OUTPUT echo "assets<> $GITHUB_OUTPUT echo "$ASSETS" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT - name: Download and extract binary if: steps.release.outputs.version != '' run: | VERSION=${{ steps.release.outputs.version }} mkdir -p /app/7zip/$VERSION # Find binary asset (prefer .7z or .tar.gz containing 7zz) ASSET_URL="" while IFS='|' read -r name url size; do if [[ "$name" == *.7z || "$name" == *.tar.gz ]]; then ASSET_URL="$url" ASSET_NAME="$name" break fi done <<< "${{ steps.release.outputs.assets }}" if [ -z "$ASSET_URL" ]; then echo "No binary asset found, skipping." exit 0 fi echo "Downloading $ASSET_NAME..." curl -L -o /tmp/asset "$ASSET_URL" echo "Extracting 7zz..." cd /tmp if [[ "$ASSET_NAME" == *.7z ]]; then 7zz x asset 7zz -o/app/7zip/$VERSION/ elif [[ "$ASSET_NAME" == *.tar.gz ]]; then tar -xzf asset --wildcards '*7zz*' -C /app/7zip/$VERSION/ || (echo "Extraction failed, may not contain 7zz"; exit 1) fi chmod +x /app/7zip/$VERSION/7zz echo "Saved 7zz to /app/7zip/$VERSION/" - name: Commit changes run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" BRANCH="update-7zip-${{ steps.release.outputs.version }}" git checkout -b $BRANCH git add /app/7zip/ || true # Add if changes detected git commit -m "Update 7-Zip to version ${{ steps.release.outputs.version }}" || echo "No changes to commit" git push origin $BRANCH - name: Create Pull Request if: steps.release.outputs.version != '' run: | BRANCH="update-7zip-${{ steps.release.outputs.version }}" curl -X POST \ -H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \ -H "Content-Type: application/json" \ -d '{ "title": "Update 7-Zip to version ${{ steps.release.outputs.version }}", "body": "Automated update of 7zz binary from GitHub release.", "head": "'$BRANCH'", "base": "main" }' \ ${{ secrets.GITEA_INSTANCE_URL || 'https://gitea.com' }}/api/v1/repos/${{ github.repository }}/pulls