Skip to content

Commit

Permalink
Release action (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcivit authored Dec 22, 2022
1 parent e3f03b3 commit 10ddbfc
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on:
push:
tags:
- '*' # Push events to matching v*, i.e. v1.0, v20.15.10
name: Upload Release Asset
jobs:
build:
name: Upload Release Asset # Name of the job
runs-on: ubuntu-latest # or windows-latest, macOS-latest
steps:
- name: Setup PHP Action
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} # Extract the version number from the tag
- name: Checkout code
uses: actions/checkout@v2 # Checkout the code
- name: Build project
run: ./bin/release.sh ${{ steps.get_version.outputs.VERSION }} # Build the project
- name: Upload Release Asset
run: |
set -x
assets=()
for asset in ./.dist/*.zip; do
assets+=("-a" "$asset")
done
tag_name="${GITHUB_REF##*/}"
hub release create "${assets[@]}" -m "Release $tag_name" "$tag_name" -d
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.env
/.idea
/cscart
.dist
42 changes: 42 additions & 0 deletions bin/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

# Exit if any command fails
set -eo pipefail

RELEASE_VERSION=$1
FILENAME_PREFIX="Plugin_CS-Cart_"
RELEASE_FOLDER=".dist"
FOLDER_PREFIX="plugin"

# If tag is not supplied, latest tag is used
if [ -z "$RELEASE_VERSION" ]
then
RELEASE_VERSION=$(git describe --tags --abbrev=0)
fi

# Remove the old release folder
rm -rf "$RELEASE_FOLDER" &&

# Create release from .git
mkdir "$RELEASE_FOLDER" &&
git archive --format zip -9 --prefix="$FOLDER_PREFIX"/ --output "$RELEASE_FOLDER"/"$FILENAME_PREFIX""$RELEASE_VERSION".zip "$RELEASE_VERSION" &&

# Unzip to manipulate the files
cd "$RELEASE_FOLDER" &&
unzip "$FILENAME_PREFIX""$RELEASE_VERSION".zip &&

# Remove zip file.
rm "$FILENAME_PREFIX""$RELEASE_VERSION".zip

# Change to the extension folder
cd "$FOLDER_PREFIX" &&

# Zip everything excluding some specific files
zip -9 -r "$FILENAME_PREFIX""$RELEASE_VERSION".zip ./src/* &&

# Move the zip file to the root of the release folder
mv "$FILENAME_PREFIX""$RELEASE_VERSION".zip ../ &&

# Remove the temporal directory to build the release
cd ../ &&
rm -rf "$FOLDER_PREFIX"
File renamed without changes.

0 comments on commit 10ddbfc

Please sign in to comment.