From cde3eb29dfd9130f52d21f6b14b06b8c96164676 Mon Sep 17 00:00:00 2001 From: Omkar Date: Wed, 18 Dec 2024 10:33:48 +0530 Subject: [PATCH] v2.0.1 -Zip + workflow --- .github/ISSUE_TEMPLATE/bug_report.md | 40 +++++++ .github/ISSUE_TEMPLATE/custom.md | 8 ++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++ .../create_release_from_manifest.yml | 87 ++++++++++++++ .github/workflows/generate_and_commit.yml | 40 +++++++ zip.sh | 112 ++++++++++++++++++ 6 files changed, 307 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/custom.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/workflows/create_release_from_manifest.yml create mode 100644 .github/workflows/generate_and_commit.yml create mode 100644 zip.sh diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..82ab942 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,40 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: 'bugs' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: + +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Version** +Version of extension + +**Environment** +Cloud foundry / NEO / CI + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (optional information):** + +- OS: [e.g. iOS] +- Browser [e.g. chrome, safari] +- Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md new file mode 100644 index 0000000..b894315 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/custom.md @@ -0,0 +1,8 @@ +--- +name: Custom issue template +about: Describe this issue template's purpose here. +title: '' +labels: '' +assignees: '' + +--- diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..8b5bd3b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: 'Feature / Enhancement' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. \ No newline at end of file diff --git a/.github/workflows/create_release_from_manifest.yml b/.github/workflows/create_release_from_manifest.yml new file mode 100644 index 0000000..1d26ce0 --- /dev/null +++ b/.github/workflows/create_release_from_manifest.yml @@ -0,0 +1,87 @@ +# Name: Create Release from Manifest | create_release_from_manifest.yml +# Developer: incpi +# Description: +# Automation: The workflow automates file generation, commits changes, and creates a GitHub release from manifest.json. +# Trigger: It triggers on pushes to the main branch, running a script to generate and commit files. +# -----------------------------------------If above fails below will not execute --------------------------------------------- +# Release: It extracts the version, finds ZIP files in the bin directory, and attaches them to the release, streamlining the process. +#__________________________________________________________________________________________________________________________ + +name: Create Release from Manifest + +on: + workflow_run: + workflows: [ "Generate and Commit Files" ] + types: + - completed + branches: + - Master + +jobs: + release: + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 # Ensures full history is fetched + + - name: Pull latest changes + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "GitHub Action" + git pull origin Master + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: "16" + + # Extract version from manifest.json + - name: Extract version from manifest.json + id: get_version + run: | + VERSION=$(jq -r '.version' manifest.json) + + # Check if the version is already in the format 1.1.1 + if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + CLEAN_VERSION="$VERSION" # Use the version as is + else + CLEAN_VERSION=$(echo "$VERSION" | awk -F. '{print $1"."$2"."$3}') # Clean to 1.1.1 + fi + + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "CLEAN_VERSION=$CLEAN_VERSION" >> $GITHUB_ENV + + - name: Find zip files in bin + id: find_zips + run: | + ZIP_FILES=$(find ./bin -type f -name "*.zip" | tr '\n' '|') # Create a pipe-separated list + echo "Found zip files: $ZIP_FILES" + echo "ZIP_FILES=$ZIP_FILES" >> $GITHUB_ENV + + - name: Create GitHub Release + id: create_release + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: "Version_${{ env.CLEAN_VERSION }}" + name: "Extension @${{ env.CLEAN_VERSION }}" # Release name + body: "Release created with version ${{ env.VERSION }}" + + - name: Attach zip files to release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + sleep 2 + IFS='|' read -r -a ZIP_ARRAY <<< "${{ env.ZIP_FILES }}" # Split the pipe-separated list into an array + for ZIP_FILE in "${ZIP_ARRAY[@]}"; do + ZIP_BASENAME=$(basename "$ZIP_FILE") # Get the clean zip file name + echo "Attaching $ZIP_BASENAME" + gh release upload "Version_${{ env.CLEAN_VERSION }}" "$ZIP_FILE" --clobber + done \ No newline at end of file diff --git a/.github/workflows/generate_and_commit.yml b/.github/workflows/generate_and_commit.yml new file mode 100644 index 0000000..b1a15d4 --- /dev/null +++ b/.github/workflows/generate_and_commit.yml @@ -0,0 +1,40 @@ +# Filename: generate_and_commit.yml +# Developer: incpi + +name: Generate and Commit Files + +on: + push: # Trigger on push for any branch + branches: + - '**' # Match all branches + +jobs: + generate_and_commit: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + # Generate files with the shell script + - name: Run Shell Script and Commit Generated Files + run: | + # Make the shell script executable and run it + chmod +x ./zip.sh + ./zip.sh + + # Configure Git + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "GitHub Action" + + # Add all newly generated files to Git + git add bin/* + git add docs/* + git commit -m "Zip generated by zip.sh on $(date)" + git push + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Prevent re-triggering the Workflow + if: contains(github.event.head_commit.message, 'Zip generated by zip.sh') + run: echo "Skipping because this is the automated commit message from our script." \ No newline at end of file diff --git a/zip.sh b/zip.sh new file mode 100644 index 0000000..a936373 --- /dev/null +++ b/zip.sh @@ -0,0 +1,112 @@ +#!/bin/bash + +set -e + +MANIFEST="manifest.json" +MANIFEST_V3="manifest.json_v3" +EXTENSION_NAME="Dark CPI Extension" +BIN_DIR="./bin" + +log_message() { + local message="$1" + local timestamp + timestamp=$(date +"%Y-%m-%d %H:%M:%S") + echo "[$timestamp] $message" +} + +log_message "Copy readme to docs. Readme.md" +cp README.md docs/readme/README.md + +log_message "----------------------" +log_message "Starting zip creation process" + +# Create bin directory if not exists +if [ ! -d "$BIN_DIR" ]; then + log_message "Creating bin directory..." + mkdir -p "$BIN_DIR" +fi + +# Clean bin directory +if [ -d "$BIN_DIR" ]; then + log_message "Deleting zip files from bin directory..." + rm -rf "$BIN_DIR"/* +fi + +create_zip() { + local manifest_file="$1" + local version_name="$2" + local output_zip="$3" + + log_message "Creating ZIP for $version_name using $manifest_file..." + + name="" + version="" + + # Extract name and version from manifest file + while IFS='' read -r line || [[ -n "$line" ]]; do + if [[ "$line" == *"\"name\":"* ]]; then + name=$(echo "$line" | awk -F'"' '{print $4}') + elif [[ "$line" == *"\"version\":"* ]]; then + version=$(echo "$line" | awk -F'"' '{print $4}' | tr -d ',') + fi + done < "$manifest_file" + + name="${name//,/}" + name="${name// /_}" + + exclusions=("./docs/*" "./node_modules" "*.sh" "./bin/*" "*.md" "./.*") + + exclude_args=() + for pattern in "${exclusions[@]}"; do + exclude_args+=(-o -path "$pattern") + done + exclude_args=( "${exclude_args[@]:1}" ) + + rm -f "$BIN_DIR/$output_zip" + + files_to_zip=$(find . -type f ! \( "${exclude_args[@]}" \)) + + if [ -z "$files_to_zip" ]; then + log_message "No files found to zip for $version_name. Exiting." + exit 1 + fi + + echo "$files_to_zip" | zip -@ "$BIN_DIR/$output_zip" + + log_message "ZIP file created: $BIN_DIR/$output_zip" +} + +process_manifest() { + local manifest_file="$1" + local version_name="$2" + local output_zip="$3" + + if [ -f "$manifest_file" ]; then + log_message "$version_name manifest found." + create_zip "$manifest_file" "$version_name" "$output_zip" + else + log_message "$version_name manifest not found. Skipping." + fi +} + +log_message "Checking manifest.json for version" +version=$(jq -r '.version' "$MANIFEST") + +if [ "$version" == "null" ]; then + log_message "Could not determine the version from manifest.json. Exiting." + exit 1 +fi + +manifest_version=$(jq -r '.manifest_version' "$MANIFEST") + +if [ "$manifest_version" == "3" ]; then + log_message "Manifest version 3 detected (Chrome)" + create_zip "$MANIFEST" "Chrome" "$EXTENSION_NAME.zip" +else + log_message "Unknown or unsupported manifest version in manifest.json!" + exit 1 +fi + +process_manifest "$MANIFEST_V3" "Chrome" "$EXTENSION_NAME.zip" + +log_message "ZIP creation process completed." \ No newline at end of file