Create Release from Manifest #5
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: 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 |