From 083f8afc398c48e69cc9a6bf8f7b498e18850a7c Mon Sep 17 00:00:00 2001 From: rajeev Date: Mon, 8 Apr 2024 20:06:43 +0530 Subject: [PATCH] updating workflow --- .github/workflows/pr.yml | 95 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 2caad24..d15559c 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -3,7 +3,8 @@ name: Generate JSON and Save as Artifacts on: push jobs: - generate-json-and-save-as-artifacts: + build: + name: generate-json-and-save-as-artifacts runs-on: windows-latest steps: @@ -20,7 +21,7 @@ jobs: run: | echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > .npmrc npm install - + - name: Set up Python uses: actions/setup-python@v5 with: @@ -40,3 +41,93 @@ jobs: with: name: generated-json path: data/ + release: + name: Release + runs-on: ubuntu-latest + permissions: + contents: write + checks: write + pull-requests: read + needs: + - build + if: ${{ (endsWith(github.base_ref, 'main') && (contains(github.head_ref, 'release/')) || github.event.pull_request.merged ) }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + fetch-tags: true + - name: Get RC Version + id: lasttag + run: | + COMMIT="${{github.sha}}" + if ${{contains(github.head_ref, 'release/')}}; then + V="${{github.head_ref}}" + V="${V#release/}" + else + V="$(npm pkg get version)" + echo "Extracted Version: $V" + V="$(echo v"$V" | sed 's/\"//g')" + echo "Cleaned up Version: $V" + fi + + # Check to see if the version tag already exists + # If it does, print a message and exit with an error code + if [ $(git tag --list "$V") ]; then + echo "Version tag already exists. Did you bump the version number?" + exit 1 + fi + + # Create an RC release if + # 1) This PR is a release branch that hasn't been merged to main. + # 2) This is a feature branch being merged into the main branch. + if ${{(! github.event.pull_request.merged && contains(github.head_ref, 'release/')) || (github.event.pull_request.merged && !contains(github.head_ref, 'release/'))}}; then + V="${V}-$(git tag --list ${V}* | wc -l)" + echo "RC Version: $V" + fi + + CL=${V#v} + CL=${CL%-*} + + echo "version=${V}" >> $GITHUB_OUTPUT + echo "cl_version=${CL}" >> $GITHUB_OUTPUT + echo "commit=${COMMIT}" >> $GITHUB_OUTPUT + + - run: "git tag --list ${V}*" + - name: Get Artifacts + uses: actions/download-artifact@v3 + with: + name: package + path: extension + - name: Get SBOM + uses: actions/download-artifact@v3 + with: + name: software-bom + path: sbom + - name: Get Changelog for this Tag + id: changelog + uses: coditory/changelog-parser@v1 + with: + version: ${{steps.lasttag.outputs.cl_version}} + - name: Create Release + uses: ncipollo/release-action@v1 + with: + name: ${{steps.lasttag.outputs.version}} + artifacts: "extension/*.vsix,sbom/**/*" + body: | + ## Features Requests / Bugs + + If you find issues or have a feature request, please enter a [new issue on GitHub](${{github.server_url}}/${{github.repository}}/issues/new). + + ## Installation + + View the installation instructions in the [README](${{github.server_url}}/${{github.repository}}/blob/main/README.md) + + ## Changelog + + ${{steps.changelog.outputs.description}} + + prerelease: ${{ (! github.event.pull_request.merged) || (github.event.pull_request.merged && ! contains(github.head_ref, 'release/')) }} + commit: ${{steps.lasttag.outputs.commit}} + makeLatest: true + tag: ${{steps.lasttag.outputs.version}}