Skip to content

Merge pull request #35 from Incpi/test #26

Merge pull request #35 from Incpi/test

Merge pull request #35 from Incpi/test #26

Workflow file for this run

# Name: Create Release from Manifest
# 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:
push:
branches:
- Master
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."
release:
runs-on: ubuntu-latest
needs: generate_and_commit
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "16"
# This step uses jq to extract the version field from the manifest.json file
- 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
# Looks for the zip file within the bin folder
- 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 }}"
# Ensures that the zip file is uploaded with the correct name and content type
- 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