From 5206bd844957d89bb633ebe5c64af5b0284304e4 Mon Sep 17 00:00:00 2001 From: Dani Akash Date: Tue, 2 Apr 2024 18:33:18 +0530 Subject: [PATCH] ci: setup release pipeline (#5) Release-As: 0.0.1 --- .github/workflows/build.yml | 2 +- .github/workflows/npm-publish.yml | 36 +++++++++++++++ .github/workflows/release-please.yml | 66 ++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/npm-publish.yml create mode 100644 .github/workflows/release-please.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6ec5212..620ade3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Use Node.js 14.x + - name: Use Node.js uses: actions/setup-node@v4 with: node-version: "20.11.0" diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..f7d7601 --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,36 @@ +# 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: Publish package to npm + +on: + repository_dispatch: + types: [publish-new-version] + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.11.0" + - name: Install dependencies + run: npm ci + - name: Lint + run: npm run lint + - name: Run tests + run: npm run test + env: + VITE_CLARIFAI_USER_ID: ${{ secrets.VITE_CLARIFAI_USER_ID }} + VITE_CLARIFAI_PAT: ${{ secrets.VITE_CLARIFAI_PAT }} + - name: Build + run: npm run build + - name: Publish to npm + run: npm publish --access public + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000..4e86ce2 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,66 @@ +name: Release + +on: + push: + branches: + - main + +permissions: + contents: write + pull-requests: write + +jobs: + + check_commit_message: + runs-on: ubuntu-latest + outputs: + patternMatch: ${{ steps.check_pattern.outputs.match }} + isReleaseComplete: ${{ steps.check_pattern.outputs.release_complete }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Check for release pattern in commit message + id: check_pattern + run: | + PATTERN="Release-As: [0-9]+\.[0-9]+\.[0-9]+|release [0-9]+\.[0-9]+\.[0-9]+" + COMMIT_MESSAGE=$(git log --format=%B -n 1) + echo "Commit Message: $COMMIT_MESSAGE" + if [[ "$COMMIT_MESSAGE" =~ $PATTERN ]]; then + echo "Pattern found. Proceeding with the job." + echo "::set-output name=match::true" + else + echo "Pattern not found. Skipping subsequent steps." + echo "::set-output name=match::false" + fi + PATTERN="release [0-9]+\.[0-9]+\.[0-9]+" + COMMIT_MESSAGE=$(git log --format=%B -n 1) + echo "Commit Message: $COMMIT_MESSAGE" + if [[ "$COMMIT_MESSAGE" =~ $PATTERN ]]; then + echo "Pattern found. Proceeding with the job." + echo "::set-output name=release_complete::true" + else + echo "Pattern not found. Skipping subsequent steps." + echo "::set-output name=release_complete::false" + fi + + release-please: + needs: check_commit_message + runs-on: ubuntu-latest + if: needs.check_commit_message.outputs.patternMatch == 'true' + steps: + - uses: google-github-actions/release-please-action@v4 + with: + release-type: node + + trigger-publish-dispatch: + name: "Trigger Publish Repository Dispatch Event" + needs: [release-please, check_commit_message] + runs-on: ubuntu-latest + if: needs.check_commit_message.outputs.isReleaseComplete == 'true' + steps: + - name: Create Release Repository Dispatch Event + id: create_release_dispatch + uses: peter-evans/repository-dispatch@v3 + with: + event-type: publish-new-version