From c89c27d35105ee380f4aaaa4a9fd9f4f4bf1da75 Mon Sep 17 00:00:00 2001 From: Loan J Date: Wed, 21 Feb 2024 18:46:33 -0500 Subject: [PATCH 1/2] Add release creation workflow --- .github/workflows/build-release.yml | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/build-release.yml diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml new file mode 100644 index 00000000..f4baf894 --- /dev/null +++ b/.github/workflows/build-release.yml @@ -0,0 +1,42 @@ +name: Release + +on: + push: + branches: + - main # or whatever branch you want to use + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Get commit hash + id: get_hash + run: | + HASH=$(git rev-parse --short "$GITHUB_SHA") + echo "::set-output name=hash::$HASH" + + - name: Create GitHub release + uses: actions/github-script@v5 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const release = await github.rest.repos.createRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: `v${{ steps.get_hash.outputs.hash }}`, + name: `v${{ steps.get_hash.outputs.hash }}`, + body: 'Automatically created new release', + }) + console.log(`Created release ${release.data.html_url}`) + + - name: Upload package to GitHub release + uses: actions/upload-artifact@v3 + with: + name: package + path: . + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From a3eb7157f0144c90856821b748c8e541d30a3fa0 Mon Sep 17 00:00:00 2001 From: Loan J Date: Thu, 22 Feb 2024 12:06:20 -0500 Subject: [PATCH 2/2] Update build-release.yml --- .github/workflows/build-release.yml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index f4baf894..fa3fa296 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -13,11 +13,18 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - - name: Get commit hash - id: get_hash + - name: Check for changes in package.json run: | - HASH=$(git rev-parse --short "$GITHUB_SHA") - echo "::set-output name=hash::$HASH" + git diff --cached --diff-filter=d package.json || { + echo "No changes to package.json" + exit 1 + } + + - name: Get version number from package.json + id: get_version + run: | + VERSION=$(jq -r '.version' package.json) + echo "::set-output name=version::$VERSION" - name: Create GitHub release uses: actions/github-script@v5 @@ -27,8 +34,8 @@ jobs: const release = await github.rest.repos.createRelease({ owner: context.repo.owner, repo: context.repo.repo, - tag_name: `v${{ steps.get_hash.outputs.hash }}`, - name: `v${{ steps.get_hash.outputs.hash }}`, + tag_name: `v${{ steps.get_version.outputs.version }}`, + name: `v${{ steps.get_version.outputs.version }}`, body: 'Automatically created new release', }) console.log(`Created release ${release.data.html_url}`)