Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit 6840af1

Browse files
committed
add release workflow
1 parent bcd1705 commit 6840af1

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

.github/workflows/release.yaml

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# For details see: https://superface.ai/blog/npm-publish-gh-actions-changelog
2+
name: Release package
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
release-type:
8+
type: choice
9+
required: true
10+
description:
11+
'The release type that will be passed to npm version command'
12+
options:
13+
[
14+
'patch',
15+
'minor',
16+
'major',
17+
'prepatch',
18+
'preminor',
19+
'premajor',
20+
'prerelease',
21+
]
22+
23+
jobs:
24+
release:
25+
name: Release
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- name: Ensure running on main branch
30+
if: github.ref_name != github.event.repository.default_branch
31+
run: |
32+
echo "This workflow must not be triggered on a branch other than main"
33+
exit 1
34+
35+
# Checkout project repository
36+
- name: Checkout
37+
uses: actions/checkout@v4
38+
with:
39+
# Using deploy key to push changes to repository
40+
# See: https://stackoverflow.com/a/76135647
41+
ssh-key: ${{ secrets.DEPLOY_KEY }}
42+
43+
# Configure Git
44+
- name: Git configuration
45+
run: |
46+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
47+
git config --global user.name "GitHub Actions"
48+
49+
# Setup Node.js environment
50+
- name: Setup Node.js
51+
uses: actions/setup-node@v4
52+
with:
53+
node-version: 20
54+
cache: 'yarn'
55+
registry-url: https://registry.npmjs.org/
56+
57+
# Bump package version
58+
# Use tag 'latest'
59+
- name: Bump release version
60+
if: startsWith(github.event.inputs.release-type, 'pre') != true
61+
run: |
62+
echo "TAG_NAME=$(npm --no-git-tag-version version $RELEASE_TYPE)" >> $GITHUB_ENV
63+
echo "RELEASE_TAG=latest" >> $GITHUB_ENV
64+
env:
65+
RELEASE_TYPE: ${{ github.event.inputs.release-type }}
66+
67+
# Bump package pre-release version
68+
# Use tag 'beta'
69+
- name: Bump pre-release version
70+
if: startsWith(github.event.inputs.release-type, 'pre')
71+
run: |
72+
echo "TAG_NAME=$(npm --no-git-tag-version --preid=beta version $RELEASE_TYPE)" >> $GITHUB_ENV
73+
echo "RELEASE_TAG=beta" >> $GITHUB_ENV
74+
env:
75+
RELEASE_TYPE: ${{ github.event.inputs.release-type }}
76+
77+
- name: Build and bump package version in the example
78+
run: |
79+
yarn install --frozen-lockfile && cd example
80+
yarn upgrade @fishjam-dev/react-native-client && cd ..
81+
82+
# Commit changes
83+
- name: Commit changed files and create a new tag
84+
run: |
85+
git add package.json yarn.lock example/yarn.lock
86+
git commit -m "Release ${{ env.TAG_NAME }}"
87+
git tag ${{ env.TAG_NAME }}
88+
89+
# Publish version to public repository
90+
- name: Publish
91+
run: npm publish --verbose --access public --tag ${{ env.RELEASE_TAG }}
92+
env:
93+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
94+
95+
# Push repository changes
96+
- name: Push changes to repository
97+
run: |
98+
git push origin && git push --tags
99+
env:
100+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
102+
# Create GitHub release with autogenerated notes
103+
- name: Create GitHub release
104+
uses: softprops/action-gh-release@v2
105+
with:
106+
name: 'Release ${{ env.TAG_NAME }}'
107+
tag_name: ${{ env.TAG_NAME }}
108+
prerelease: ${{ startsWith(github.event.inputs.release-type, 'pre') }}
109+
generate_release_notes: true
110+
env:
111+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)