write a workflow to create zip folders for any sample app that is not… #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Package Applications | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
pull_request: | |
jobs: | |
package-applications: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.head_ref || github.ref_name }} | |
fetch-depth: 0 | |
- name: Package applications | |
run: | | |
# Initialize the file to store folder names | |
folder_list_file="packaged_samples_apps.txt" | |
echo "Processed folders:" > $folder_list_file | |
# Find all directories at the root level | |
for folder in $(find . -mindepth 1 -maxdepth 1 -type d -exec basename {} \;); do | |
echo "Processing folder: $folder" | |
# Check if the folder is a Java or Python project | |
if find $folder -type f \( -name "*.java" -o -name "*.py" \) | grep -q .; then | |
echo "Skipping $folder as it is a Java or Python project." | |
continue | |
fi | |
# Check for changes or if the zip file does not already exist | |
if git diff --quiet HEAD^ -- $folder && [ -f "$folder/application.zip" ]; then | |
echo "No changes and zip already exists for $folder. Skipping." | |
continue | |
fi | |
echo "Creating zip for $folder" | |
# Check if .vespaignore exists and create exclude list | |
exclude_args="" | |
if [ -f "$folder/.vespaignore" ]; then | |
while IFS= read -r line || [ -n "$line" ]; do | |
exclude_args="$exclude_args --exclude=$line" | |
done < "$folder/.vespaignore" | |
fi | |
# Create the zip inside the folder | |
(cd $folder && zip -r application.zip . $exclude_args) | |
# Add the folder name to the list | |
echo "$folder" >> $folder_list_file | |
done | |
- name: Upload zip files | |
uses: actions/upload-artifact@v4 | |
with: | |
name: applications | |
path: "*.zip" | |
- name: Upload processed folder list | |
uses: actions/upload-artifact@v2 | |
with: | |
name: packaged_samples_apps | |
path: packaged_samples_apps.txt | |
# Configure Git | |
- name: Configure Git | |
run: | | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "[email protected]" | |
# Commit and push changes | |
- name: Commit and Push Changes | |
run: | | |
git add . | |
git commit -m "Create application.zip for new or editted folders" || echo "No application.zips created" | |
git push origin ${{ github.ref_name }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |