Skip to content

Commit 5b98dd1

Browse files
authored
ci: automating releases (#461)
1 parent dbfc267 commit 5b98dd1

File tree

3 files changed

+141
-1
lines changed

3 files changed

+141
-1
lines changed

.github/workflows/bump_version.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Bump Version
2+
3+
permissions:
4+
contents: write
5+
pull-requests: write
6+
7+
# Only works right now through manual requests
8+
on:
9+
push:
10+
branches:
11+
- 'cdActions'
12+
workflow_dispatch:
13+
branches:
14+
- 'cdActions'
15+
- 'master'
16+
inputs:
17+
version:
18+
description: 'Semver type of new version (major / minor / patch)'
19+
required: false
20+
type: choice
21+
default: patch
22+
options:
23+
- patch
24+
- minor
25+
- major
26+
workspace:
27+
description: 'Workspace to release. e.g. @segment/analytics-react-native'
28+
required: false
29+
type: string
30+
default: '@segment/analytics-react-native'
31+
32+
jobs:
33+
bump-version:
34+
name: Bump Version
35+
runs-on: ubuntu-latest
36+
37+
steps:
38+
- name: Check out source
39+
uses: actions/checkout@v2
40+
41+
- name: Setup Node.js
42+
uses: actions/setup-node@v2
43+
with:
44+
node-version: '14'
45+
cache: 'yarn'
46+
47+
- name: Install packages
48+
run: yarn install --frozen-lockfile
49+
50+
- name: Build
51+
run: yarn build
52+
53+
- name: Set Environment Variables
54+
env:
55+
IS_PUSH: ${{ github.event_name == 'push' }}
56+
run: |
57+
if ${IS_PUSH}; then
58+
echo "VERSION=patch" >> $GITHUB_ENV
59+
echo "WORKSPACE='@segment/analytics-react-native'" >> $GITHUB_ENV
60+
echo "Set the default input params: VERSION=patch, WORKSPACE='@segment/analytics-react-native'"
61+
else
62+
echo "VERSION=${{github.event.inputs.version}}" >> $GITHUB_ENV
63+
echo "WORKSPACE=${{github.event.inputs.workspace}}" >> $GITHUB_ENV
64+
echo "Setting user input params: VERSION=${{github.event.inputs.version}}, WORKSPACE=${{github.event.inputs.workspace}}"
65+
fi
66+
67+
68+
- name: Bump Version
69+
run: yarn workspace ${{ env.WORKSPACE }} version --${{ env.VERSION }} --no-git-tag-version
70+
71+
- name: Create Pull Request
72+
uses: peter-evans/create-pull-request@v3
73+
with:
74+
commit-message: 'chore: release ${{env.WORKSPACE}} ${{env.VERSION}}'
75+
title: 'chore: release ${{env.WORKSPACE}} ${{env.VERSION}}'
76+
delete-branch: true

.github/workflows/publish.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- 'cdActions'
7+
tags:
8+
- 'v*'
9+
paths:
10+
- 'packages/core/**'
11+
# workflow_dispatch:
12+
# inputs:
13+
# workspace:
14+
# description: 'Workspace to publish e.g. @segment/analytics-react-native'
15+
# required: false
16+
# type: string
17+
# default: '@segment/analytics-react-native'
18+
# secrets:
19+
# NPM_TOKEN:
20+
# required: true
21+
22+
jobs:
23+
publish:
24+
name: Publish to npm
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v2
28+
29+
- uses: actions/setup-node@v2
30+
with:
31+
node-version: '14'
32+
cache: 'yarn'
33+
34+
- name: Config and Build
35+
run: |
36+
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
37+
yarn install --frozen-lockfile
38+
yarn build
39+
env:
40+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
41+
42+
- name: Publish
43+
working-directory: packages/core
44+
run: npm publish --tag beta --dry-run
45+
46+
create-github-release:
47+
if: github.event.inputs.workspace == '' || github.event.inputs.workspace == '@segment/analytics-react-native'
48+
name: Create GitHub Release
49+
permissions:
50+
contents: write
51+
runs-on: ubuntu-latest
52+
needs: publish
53+
steps:
54+
- name: Create Release Notes
55+
uses: actions/[email protected]
56+
57+
with:
58+
script: |
59+
await github.request(`POST /repos/${{ github.repository }}/releases`, {
60+
tag_name: "${{ github.ref }}",
61+
generate_release_notes: true,
62+
draft: true
63+
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@
4848
},
4949
"engines": {
5050
"node": ">=12"
51-
}
51+
},
52+
"version": "0.0.1"
5253
}

0 commit comments

Comments
 (0)