diff --git a/.github/workflows/versioning.yml b/.github/workflows/versioning.yml new file mode 100644 index 00000000..2687aae1 --- /dev/null +++ b/.github/workflows/versioning.yml @@ -0,0 +1,70 @@ +name: Update Version on Dev Push +on: + push: + branches: + - dev + +jobs: + update-version: + if: ${{contains(toJSON(github.event.head_commit.message), 'Bump version') == false}} + runs-on: ubuntu-latest + + steps: + - name: Get version type + id: version_type + run: | + if [[ ${{ contains(toJSON(github.event.head_commit.message), 'bump_major') }} == true ]]; then + echo "VERSION_TYPE=major" >> $GITHUB_OUTPUT + elif [[ ${{ contains(toJSON(github.event.head_commit.message), 'bump_minor') }} == true ]]; then + echo "VERSION_TYPE=minor" >> $GITHUB_OUTPUT + else + echo "VERSION_TYPE=patch" >> $GITHUB_OUTPUT + fi + shell: bash + + - name: Checkout code + uses: actions/checkout@v3 + with: + token: ${{ secrets.ACTIONS_BOT_TOKEN }} + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: 14 # Adjust this to your desired Node.js version + + - name: Set Git user information + run: | + git config --local user.name "bot-edgepi" + git config --local user.email "120603722+bot-edgepi@users.noreply.github.com" + + - name: Set versioned branch name + id: branch-name + run: | + echo "version-$(date +'%Y%m%d%H%M%S')-$(openssl rand -hex 4)" > branch-name.txt + echo "BRANCH_NAME=$(cat branch-name.txt)" >> $GITHUB_ENV + + - name: Checkout new branch + run: | + branch_name=$(cat branch-name.txt) + git checkout -b $branch_name + git push --set-upstream origin $branch_name + + - name: Bump version + run: | + npm version ${{ steps.version_type.outputs.VERSION_TYPE }} --force + + - name: Push to the dev branch + run: | + branch_name=$(cat branch-name.txt) + version=$(cat package.json | jq -r '.version') + git add . + git commit -m "Bump version to $version" + git push --follow-tags + git push --force origin "$branch_name":dev + + - name: Delete versioned branch + run: | + branch_name=$(cat branch-name.txt) + git checkout dev + git branch -D $branch_name + git push origin --delete $branch_name diff --git a/branch-name.txt b/branch-name.txt new file mode 100644 index 00000000..3219bce2 --- /dev/null +++ b/branch-name.txt @@ -0,0 +1 @@ +version-20240115230022-89d79715 diff --git a/package-lock.json b/package-lock.json index f789c089..f4f924f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@edgepi-cloud/node-red-edgepi-thermocouple", - "version": "1.0.10", + "version": "1.0.11", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index faa62f1e..c23c0c43 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@edgepi-cloud/node-red-edgepi-thermocouple", - "version": "1.0.10", + "version": "1.0.11", "description": "A node-red node for EdgePi thermocouple module", "main": "edgepi-thermocouple.js", "scripts": {