Skip to content

Commit

Permalink
chore: adding github release action
Browse files Browse the repository at this point in the history
  • Loading branch information
kulak-at committed Jul 29, 2024
1 parent cf072c9 commit 785e07d
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/release-and-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Release and Publish

on:
push:
tags:
- 'v*'

jobs:
create-release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: true
prerelease: false

publish-npm:
needs: create-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

update-release:
needs: publish-npm
runs-on: ubuntu-latest
steps:
- name: Update Release
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
const tagName = context.ref.replace('refs/tags/', '');
const releases = await github.rest.repos.listReleases({ owner, repo });
const draftRelease = releases.data.find(release => release.draft && release.tag_name === tagName);
if (draftRelease) {
await github.rest.repos.updateRelease({
owner,
repo,
release_id: draftRelease.id,
draft: false,
name: `Release ${tagName}`,
body: 'This release has been automatically published to npm.'
});
}

0 comments on commit 785e07d

Please # to comment.