Skip to content

Zip Directory and Upload Artifact #1

Zip Directory and Upload Artifact

Zip Directory and Upload Artifact #1

Workflow file for this run

name: Zip Directory and Upload Artifact
on:
workflow_dispatch:
inputs:
directory_to_zip:
description: 'Directory to zip (e.g., my_folder or . for root)'
required: true
default: 'fail2ban/filter.d' # Default to the root directory
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get current date for filename
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: Create zip archive
run: |
DIR_NAME="${{ github.event.inputs.directory_to_zip }}"
ZIP_FILE_NAME="${DIR_NAME//\//_}_${{ steps.date.outputs.date }}.zip"
if [ "$DIR_NAME" == "." ]; then
# If the input is '.', zip the entire repository excluding .git and the zip file itself
echo "Zipping entire repository (excluding .git and the output zip file)..."
zip -r "$ZIP_FILE_NAME" . -x "*.git*" -x "$ZIP_FILE_NAME"
else
# Zip the specified directory
echo "Zipping directory: $DIR_NAME"
if [ -d "$DIR_NAME" ]; then
zip -r "$ZIP_FILE_NAME" "$DIR_NAME"
else
echo "Error: Directory '$DIR_NAME' not found."
exit 1
fi
fi
echo "Generated zip file: $ZIP_FILE_NAME"
echo "ZIP_FILE_NAME=$ZIP_FILE_NAME" >> $GITHUB_ENV # Set environment variable for subsequent steps
- name: Upload zip file as artifact
uses: actions/upload-artifact@v4
with:
name: zipped-directory-${{ steps.date.outputs.date }}
path: ${{ env.ZIP_FILE_NAME }}
retention-days: 7 # Keep the artifact for 7 days