Skip to content

Commit b51041f

Browse files
authored
Create zip_directory.yml
1 parent 9c0b4e3 commit b51041f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Zip Directory and Upload Artifact
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
directory_to_zip:
7+
description: 'Directory to zip (e.g., my_folder or . for root)'
8+
required: true
9+
default: 'fail2ban/filter.d' # Default to the root directory
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Get current date for filename
20+
id: date
21+
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
22+
23+
- name: Create zip archive
24+
run: |
25+
DIR_NAME="${{ github.event.inputs.directory_to_zip }}"
26+
ZIP_FILE_NAME="${DIR_NAME//\//_}_${{ steps.date.outputs.date }}.zip"
27+
28+
if [ "$DIR_NAME" == "." ]; then
29+
# If the input is '.', zip the entire repository excluding .git and the zip file itself
30+
echo "Zipping entire repository (excluding .git and the output zip file)..."
31+
zip -r "$ZIP_FILE_NAME" . -x "*.git*" -x "$ZIP_FILE_NAME"
32+
else
33+
# Zip the specified directory
34+
echo "Zipping directory: $DIR_NAME"
35+
if [ -d "$DIR_NAME" ]; then
36+
zip -r "$ZIP_FILE_NAME" "$DIR_NAME"
37+
else
38+
echo "Error: Directory '$DIR_NAME' not found."
39+
exit 1
40+
fi
41+
fi
42+
echo "Generated zip file: $ZIP_FILE_NAME"
43+
echo "ZIP_FILE_NAME=$ZIP_FILE_NAME" >> $GITHUB_ENV # Set environment variable for subsequent steps
44+
45+
- name: Upload zip file as artifact
46+
uses: actions/upload-artifact@v4
47+
with:
48+
name: zipped-directory-${{ steps.date.outputs.date }}
49+
path: ${{ env.ZIP_FILE_NAME }}
50+
retention-days: 7 # Keep the artifact for 7 days

0 commit comments

Comments
 (0)