Skip to content

Commit ba4cf9f

Browse files
authored
ci: cd cleanup and refactor working dir (#462)
1 parent 5b98dd1 commit ba4cf9f

File tree

2 files changed

+37
-32
lines changed

2 files changed

+37
-32
lines changed

.github/workflows/bump_version.yml

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ permissions:
66

77
# Only works right now through manual requests
88
on:
9-
push:
10-
branches:
11-
- 'cdActions'
129
workflow_dispatch:
1310
branches:
14-
- 'cdActions'
1511
- 'master'
1612
inputs:
1713
version:
@@ -24,10 +20,10 @@ on:
2420
- minor
2521
- major
2622
workspace:
27-
description: 'Workspace to release. e.g. @segment/analytics-react-native'
23+
description: 'Workspace to publish e.g. core, plugin-idfa'
2824
required: false
2925
type: string
30-
default: '@segment/analytics-react-native'
26+
default: 'core'
3127

3228
jobs:
3329
bump-version:
@@ -50,27 +46,24 @@ jobs:
5046
- name: Build
5147
run: yarn build
5248

53-
- name: Set Environment Variables
49+
- name: Set Working Directory
5450
env:
55-
IS_PUSH: ${{ github.event_name == 'push' }}
51+
IS_PLUGIN: ${{ startsWith(github.event.inputs.workspace, 'plugin-') }}
5652
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'"
53+
if ${IS_PLUGIN}; then
54+
echo "DIR=packages/plugins/${{github.event.inputs.workspace}}" >> $GITHUB_ENV
6155
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}}"
56+
echo "DIR=packages/${{github.event.inputs.workspace}}" >> $GITHUB_ENV
6557
fi
66-
58+
echo "Setting working directory to: WORKSPACE=$DIR"
6759
6860
- name: Bump Version
69-
run: yarn workspace ${{ env.WORKSPACE }} version --${{ env.VERSION }} --no-git-tag-version
61+
working-directory: ${{env.DIR}}
62+
run: yarn version --${{ github.event.inputs.version }} --no-git-tag-version
7063

7164
- name: Create Pull Request
7265
uses: peter-evans/create-pull-request@v3
7366
with:
74-
commit-message: 'chore: release ${{env.WORKSPACE}} ${{env.VERSION}}'
75-
title: 'chore: release ${{env.WORKSPACE}} ${{env.VERSION}}'
67+
commit-message: 'chore: release ${{env.DIR}} ${{github.event.inputs.version}}'
68+
title: 'chore: release ${{env.DIR}} ${{github.event.inputs.version}}'
7669
delete-branch: true

.github/workflows/publish.yml

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@ name: Publish
33
on:
44
push:
55
branches:
6-
- 'cdActions'
6+
- 'master'
77
tags:
88
- 'v*'
99
paths:
10+
# Only supporting core for now
1011
- '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
12+
workflow_dispatch:
13+
inputs:
14+
workspace:
15+
description: 'Workspace to publish e.g. core, plugin-idfa'
16+
required: false
17+
type: string
18+
default: 'core'
19+
secrets:
20+
NPM_TOKEN:
21+
required: true
2122

2223
jobs:
2324
publish:
@@ -39,12 +40,23 @@ jobs:
3940
env:
4041
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
4142

43+
- name: Set Working Directory
44+
env:
45+
IS_PLUGIN: ${{ startsWith(github.event.inputs.workspace, 'plugin-') }}
46+
run: |
47+
if ${IS_PLUGIN}; then
48+
echo "DIR=packages/plugins/${{github.event.inputs.workspace}}" >> $GITHUB_ENV
49+
else
50+
echo "DIR=packages/${{github.event.inputs.workspace}}" >> $GITHUB_ENV
51+
fi
52+
echo "Setting working directory to: WORKSPACE=$DIR"
53+
4254
- name: Publish
43-
working-directory: packages/core
55+
working-directory: ${{env.DIR}}
4456
run: npm publish --tag beta --dry-run
4557

4658
create-github-release:
47-
if: github.event.inputs.workspace == '' || github.event.inputs.workspace == '@segment/analytics-react-native'
59+
if: github.event.inputs.workspace == '' || github.event.inputs.workspace == 'core'
4860
name: Create GitHub Release
4961
permissions:
5062
contents: write

0 commit comments

Comments
 (0)