From 0c9dfcc7a0db537efa9c3f96a61ced65a199ffe3 Mon Sep 17 00:00:00 2001 From: TheBumpaster Date: Fri, 22 Sep 2023 09:40:32 +0200 Subject: [PATCH 1/2] create auto patcher for release based on semver tag --- .github/workflows/npm-publish.yml | 5 +--- .github/workflows/semver.yml | 41 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/semver.yml diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 6cdebaf..0be6b24 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -1,6 +1,3 @@ -# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created -# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages - name: Node.js Package on: @@ -25,7 +22,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 18 registry-url: https://registry.npmjs.org/ - run: npm ci - run: npm publish diff --git a/.github/workflows/semver.yml b/.github/workflows/semver.yml new file mode 100644 index 0000000..3beee4a --- /dev/null +++ b/.github/workflows/semver.yml @@ -0,0 +1,41 @@ +name: Update package.json version + +on: + push: + tags: + - 'v*.*.*' # This will trigger the workflow for tags in the format vx.x.x + +jobs: + update-version: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Validate and extract version from tag + id: get_version + run: | + TAG_NAME=${GITHUB_REF#refs/tags/} + VERSION=${TAG_NAME#v} + # Validate if the extracted version is in semver format + if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "::set-output name=version::$VERSION" + else + echo "Error: Invalid semver format" + exit 1 + fi + + - name: Update package.json + run: | + VERSION=${{ steps.get_version.outputs.version }} + jq ".version=\"$VERSION\"" package.json > package.tmp.json && mv package.tmp.json package.json + + - name: Commit and push changes + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add package.json + git commit -m "Update package.json version to ${{ steps.get_version.outputs.version }}" + git push https://${{ secrets.PAT_TOKEN }}@github.com/${{ github.repository }}.git HEAD:master + From b809d99ed53db9e36404b1a80eb806ec67e03cd0 Mon Sep 17 00:00:00 2001 From: TheBumpaster Date: Fri, 22 Sep 2023 10:01:34 +0200 Subject: [PATCH 2/2] update release workflows --- .github/workflows/npm-publish.yml | 2 +- .github/workflows/semver.yml | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 0be6b24..b202ac5 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 18 - run: npm ci - run: npm test diff --git a/.github/workflows/semver.yml b/.github/workflows/semver.yml index 3beee4a..bb85ff4 100644 --- a/.github/workflows/semver.yml +++ b/.github/workflows/semver.yml @@ -39,3 +39,9 @@ jobs: git commit -m "Update package.json version to ${{ steps.get_version.outputs.version }}" git push https://${{ secrets.PAT_TOKEN }}@github.com/${{ github.repository }}.git HEAD:master + - name: Create and push release branch + run: | + TAG_NAME=${GITHUB_REF#refs/tags/} + RELEASE_BRANCH=release/$TAG_NAME + git checkout -b $RELEASE_BRANCH + git push origin $RELEASE_BRANCH \ No newline at end of file