-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
136 additions
and
29 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: Getting Cache | ||
description: 'Composite action to share cache fetching between workflows' | ||
|
||
inputs: | ||
PREFIX_CACHE_KEY: | ||
description: 'Supported string values. Used as prefix to generate a cache key' | ||
required: false | ||
NODE_MODULES: | ||
description: 'Supported boolean values. Used to know if should manage the NODE MODULES cache' | ||
required: false | ||
NPM: | ||
description: 'Supported boolean values. Used to know if should manage the NPM cache' | ||
required: false | ||
|
||
outputs: | ||
cache_node_modules: | ||
description: 'Used to know if exist a NODE_MODULES cache' | ||
value: ${{ steps.cache_node_modules.outputs.cache-hit }} | ||
|
||
runs: | ||
using: composite | ||
|
||
steps: | ||
- name: 'Set unify package version' | ||
id: package | ||
shell: sh | ||
run: npm version -no-git-tag-version 0.0.0 | ||
|
||
- name: 'Get NPM cache directory path' | ||
id: cache_path | ||
shell: sh | ||
run: echo dir=$(npm config get cache) >> $GITHUB_OUTPUT | ||
|
||
- name: 'Get cache NODE MODULES dependencies' | ||
id: cache_node_modules | ||
if: inputs.NODE_MODULES == 'true' | ||
uses: actions/cache@v4 | ||
with: | ||
path: ./node_modules | ||
key: ${{ inputs.PREFIX_CACHE_KEY }}-node_modules-${{ hashFiles('**/package-lock.json') }} | ||
|
||
- name: 'Get cache NPM dependencies' | ||
id: cache_npm | ||
if: inputs.NPM == 'true' && steps.cache_node_modules.outputs.cache-hit != 'true' | ||
uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.npm | ||
${{ steps.cache_path.outputs.dir }} | ||
key: ${{ inputs.PREFIX_CACHE_KEY }}-npm-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ inputs.PREFIX_CACHE_KEY }}-npm- | ||
${{ inputs.PREFIX_CACHE_KEY }}- | ||
- name: 'Undo package version changes' | ||
shell: sh | ||
run: git checkout -- . |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Increment Version | ||
|
||
outputs: | ||
version: | ||
description: "New version" | ||
value: ${{ steps.project.outputs.version }} | ||
previous: | ||
description: "Old version" | ||
value: ${{ steps.project.outputs.previous }} | ||
|
||
runs: | ||
using: composite | ||
|
||
steps: | ||
- name: 'Increment version' | ||
id: project | ||
shell: sh | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: ${GITHUB_ACTION_PATH}/increment-version.sh |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# GET CURRENT VERSION | ||
CURRENT_BRANCH_VERSION=$(node -p "require('./package.json').version") | ||
|
||
echo "Current version: v$CURRENT_BRANCH_VERSION" | ||
echo previous=$CURRENT_BRANCH_VERSION >> $GITHUB_OUTPUT | ||
echo version=$CURRENT_BRANCH_VERSION >> $GITHUB_OUTPUT | ||
|
||
# GET LAST RELEASE VERSION AND COMMITS | ||
git fetch --tags | ||
LAST_RELEASE_TAG=$(git tag -l "v*" | sort -V | grep -E "^v[0-9]+(\.[0-9]+)*$" | tail -1) | ||
if [ -z "$LAST_RELEASE_TAG" ]; then | ||
LAST_RELEASE_VERSION="0.0.0" | ||
echo "There is no last release, starting from v$LAST_RELEASE_VERSION" | ||
LAST_RELEASE_ID=$(git rev-list --max-parents=0 HEAD) | ||
else | ||
LAST_RELEASE_VERSION=$(expr "$LAST_RELEASE_TAG" : "v\(.*\)") | ||
echo "Last released version: v$LAST_RELEASE_VERSION" | ||
LAST_RELEASE_ID=$LAST_RELEASE_TAG | ||
fi | ||
|
||
COMMITS=$(git log --pretty=format:"%B" "$LAST_RELEASE_ID"..) | ||
if [ "$COMMITS" == "" ]; then | ||
echo "No changes from the last version ($LAST_RELEASE_VERSION). No version number change required." | ||
exit 0; | ||
fi | ||
|
||
# FIGURE OUT NEXT VERSION | ||
if echo "$COMMITS" | grep -qE "^BREAKING[ -]CHANGE: "; then | ||
CURRENT_MAJOR=$(echo "$LAST_RELEASE_VERSION" | sed -E "s|^([0-9]+)\.([0-9]+)\.([0-9]+)|\1|") | ||
NEXT_VERSION=$(echo "$LAST_RELEASE_VERSION" | sed -E "s|([0-9]+)\.([0-9]+)\.([0-9]+)|$(( CURRENT_MAJOR + 1 )).0.0|") | ||
elif echo "$COMMITS" | grep -qE "^feat: |^feat\(.*\): "; then | ||
CURRENT_MINOR=$(echo "$LAST_RELEASE_VERSION" | sed -E "s|^([0-9]+)\.([0-9]+)\.([0-9]+)|\2|") | ||
NEXT_VERSION=$(echo "$LAST_RELEASE_VERSION" | sed -E "s|([0-9]+)\.([0-9]+)\.([0-9]+)|\1.$(( CURRENT_MINOR + 1 )).0|") | ||
else | ||
CURRENT_PATCH=$(echo "$LAST_RELEASE_VERSION" | sed -E "s|^([0-9]+)\.([0-9]+)\.([0-9]+)|\3|") | ||
NEXT_VERSION=$(echo "$LAST_RELEASE_VERSION" | sed -E "s|([0-9]+)\.([0-9]+)\.([0-9]+)|\1.\2.$(( CURRENT_PATCH + 1 ))|") | ||
fi | ||
|
||
versions=$(printf '%s\n%s' "$NEXT_VERSION" "$CURRENT_BRANCH_VERSION") | ||
if [ "$NEXT_VERSION" == "$CURRENT_BRANCH_VERSION" ] || [ "$versions" == "$(sort -V <<< "$versions")" ]; then | ||
echo "Version is updated, no changes required!" >&2 | ||
exit 0 | ||
fi | ||
|
||
echo "Suggested new version: $NEXT_VERSION" | ||
echo version=$NEXT_VERSION >> $GITHUB_OUTPUT | ||
|
||
## UPDATE VERSION | ||
npm version -no-git-tag-version --force $NEXT_VERSION |
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
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