Skip to content

ci: cd cleanup and refactor working dir #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ permissions:

# Only works right now through manual requests
on:
push:
branches:
- 'cdActions'
workflow_dispatch:
branches:
- 'cdActions'
- 'master'
inputs:
version:
Expand All @@ -24,10 +20,10 @@ on:
- minor
- major
workspace:
description: 'Workspace to release. e.g. @segment/analytics-react-native'
description: 'Workspace to publish e.g. core, plugin-idfa'
required: false
type: string
default: '@segment/analytics-react-native'
default: 'core'

jobs:
bump-version:
Expand All @@ -50,27 +46,24 @@ jobs:
- name: Build
run: yarn build

- name: Set Environment Variables
- name: Set Working Directory
env:
IS_PUSH: ${{ github.event_name == 'push' }}
IS_PLUGIN: ${{ startsWith(github.event.inputs.workspace, 'plugin-') }}
run: |
if ${IS_PUSH}; then
echo "VERSION=patch" >> $GITHUB_ENV
echo "WORKSPACE='@segment/analytics-react-native'" >> $GITHUB_ENV
echo "Set the default input params: VERSION=patch, WORKSPACE='@segment/analytics-react-native'"
if ${IS_PLUGIN}; then
echo "DIR=packages/plugins/${{github.event.inputs.workspace}}" >> $GITHUB_ENV
else
echo "VERSION=${{github.event.inputs.version}}" >> $GITHUB_ENV
echo "WORKSPACE=${{github.event.inputs.workspace}}" >> $GITHUB_ENV
echo "Setting user input params: VERSION=${{github.event.inputs.version}}, WORKSPACE=${{github.event.inputs.workspace}}"
echo "DIR=packages/${{github.event.inputs.workspace}}" >> $GITHUB_ENV
fi

echo "Setting working directory to: WORKSPACE=$DIR"

- name: Bump Version
run: yarn workspace ${{ env.WORKSPACE }} version --${{ env.VERSION }} --no-git-tag-version
working-directory: ${{env.DIR}}
run: yarn version --${{ github.event.inputs.version }} --no-git-tag-version

- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
commit-message: 'chore: release ${{env.WORKSPACE}} ${{env.VERSION}}'
title: 'chore: release ${{env.WORKSPACE}} ${{env.VERSION}}'
commit-message: 'chore: release ${{env.DIR}} ${{github.event.inputs.version}}'
title: 'chore: release ${{env.DIR}} ${{github.event.inputs.version}}'
delete-branch: true
38 changes: 25 additions & 13 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ name: Publish
on:
push:
branches:
- 'cdActions'
- 'master'
tags:
- 'v*'
paths:
# Only supporting core for now
- 'packages/core/**'
# workflow_dispatch:
# inputs:
# workspace:
# description: 'Workspace to publish e.g. @segment/analytics-react-native'
# required: false
# type: string
# default: '@segment/analytics-react-native'
# secrets:
# NPM_TOKEN:
# required: true
workflow_dispatch:
inputs:
workspace:
description: 'Workspace to publish e.g. core, plugin-idfa'
required: false
type: string
default: 'core'
secrets:
NPM_TOKEN:
required: true

jobs:
publish:
Expand All @@ -39,12 +40,23 @@ jobs:
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Set Working Directory
env:
IS_PLUGIN: ${{ startsWith(github.event.inputs.workspace, 'plugin-') }}
run: |
if ${IS_PLUGIN}; then
echo "DIR=packages/plugins/${{github.event.inputs.workspace}}" >> $GITHUB_ENV
else
echo "DIR=packages/${{github.event.inputs.workspace}}" >> $GITHUB_ENV
fi
echo "Setting working directory to: WORKSPACE=$DIR"

- name: Publish
working-directory: packages/core
working-directory: ${{env.DIR}}
run: npm publish --tag beta --dry-run

create-github-release:
if: github.event.inputs.workspace == '' || github.event.inputs.workspace == '@segment/analytics-react-native'
if: github.event.inputs.workspace == '' || github.event.inputs.workspace == 'core'
name: Create GitHub Release
permissions:
contents: write
Expand Down