Skip to content

ci: automating releases #461

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 19 commits 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
76 changes: 76 additions & 0 deletions .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Bump Version

permissions:
contents: write
pull-requests: write

# Only works right now through manual requests
on:
push:
branches:
- 'cdActions'
workflow_dispatch:
branches:
- 'cdActions'
- 'master'
inputs:
version:
description: 'Semver type of new version (major / minor / patch)'
required: false
type: choice
default: patch
options:
- patch
- minor
- major
workspace:
description: 'Workspace to release. e.g. @segment/analytics-react-native'
required: false
type: string
default: '@segment/analytics-react-native'

jobs:
bump-version:
name: Bump Version
runs-on: ubuntu-latest

steps:
- name: Check out source
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
cache: 'yarn'

- name: Install packages
run: yarn install --frozen-lockfile

- name: Build
run: yarn build

- name: Set Environment Variables
env:
IS_PUSH: ${{ github.event_name == 'push' }}
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'"
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}}"
fi


- name: Bump Version
run: yarn workspace ${{ env.WORKSPACE }} version --${{ env.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}}'
delete-branch: true
63 changes: 63 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Publish

on:
push:
branches:
- 'cdActions'
tags:
- 'v*'
paths:
- '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

jobs:
publish:
name: Publish to npm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
node-version: '14'
cache: 'yarn'

- name: Config and Build
run: |
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
yarn install --frozen-lockfile
yarn build
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish
working-directory: packages/core
run: npm publish --tag beta --dry-run

create-github-release:
if: github.event.inputs.workspace == '' || github.event.inputs.workspace == '@segment/analytics-react-native'
name: Create GitHub Release
permissions:
contents: write
runs-on: ubuntu-latest
needs: publish
steps:
- name: Create Release Notes
uses: actions/[email protected]

with:
script: |
await github.request(`POST /repos/${{ github.repository }}/releases`, {
tag_name: "${{ github.ref }}",
generate_release_notes: true,
draft: true
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
},
"engines": {
"node": ">=12"
}
},
"version": "0.0.1"
}