Skip to content

Commit

Permalink
create composite actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Joli Lui committed Jul 14, 2023
1 parent 70e7bcc commit dfef810
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 117 deletions.
39 changes: 39 additions & 0 deletions .github/actions/release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: GitHub release and Publish to NPM
description: Create a GitHub release and publish to NPM

inputs:
github-token:
required: true
description: 'The GitHub token to use for authentication'
release-tag:
required: true
description: 'The tag to use for the release'
draft:
required: false
description: 'Whether to create a draft (unpublished) release'
default: 'true'
prerelease:
required: false
description: 'Whether to create a prerelease release'
default: 'true'

runs:
using: 'composite'
steps:
# Replace with DevCycleHQ/release-action/gh-release@main when it's ready
- name: Create GitHub Release
uses: ncipollo/release-action@v1
with:
name: "${{ inputs.release-tag }}"
tag: "${{ inputs.release-tag }}"
generateReleaseNotes: "true"
makeLatest: "true"
token: ${{ inputs.github-token }}
draft: ${{ inputs.draft }}
prerelease: ${{ inputs.prerelease }}

- name: Publish to NPM
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.NPMJS_ACCESS_TOKEN }}
run: npm publish --access public
55 changes: 55 additions & 0 deletions .github/actions/update-doc/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Update Doc

description: 'Update the CLI version in devcycle-docs'

inputs:
latest_tag:
required: true
description: 'The latest tag from the workflow that uses this action'
access_token:
required: true
description: 'The access token to use for authentication'

runs:
using: 'composite'
steps:
- name: Check out code
uses: actions/checkout@v3
with:
repository: DevCycleHQ/devcycle-docs
path: devcycle-docs
token: ${{ inputs.access_token }}
fetch-depth: 0

- name: Set Git author
shell: bash
working-directory: devcycle-docs
run: |
git config --global user.email "[email protected]"
git config --global user.name "DevCycle Automation"
- name: Set branch name
shell: bash
working-directory: devcycle-docs
run: echo "BRANCH_NAME=update-cli-version-to-${{ inputs.latest_tag }}" >> $GITHUB_ENV

- name: Update CLI version in docs repo
shell: bash
working-directory: devcycle-docs
run: |
git checkout -b "$BRANCH_NAME"
sed -i "s/const DVC_CLI_VERSION = .*/const DVC_CLI_VERSION = '${{ inputs.latest_tag }}' \/\/ auto updated by dvc cli release workflow/" docusaurus.config.js
git add docusaurus.config.js
git commit -m "Update CLI version to ${{ inputs.latest_tag }}"
- name: Push code to docs repo
shell: bash
working-directory: devcycle-docs
run: git push --set-upstream origin "$BRANCH_NAME"

- name: Create PR
shell: bash
working-directory: devcycle-docs
env:
GH_TOKEN: ${{ inputs.access_token }}
run: gh pr create --repo DevCycleHQ/devcycle-docs --base main --head "$BRANCH_NAME" --title "Update CLI version to $LATEST_TAG" --body "This PR was automatically created by the DevCycle CLI release workflow."
88 changes: 88 additions & 0 deletions .github/workflows/cli-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: CLI Release

on:
workflow_dispatch:
inputs:
draft-release:
description: 'Draft release?'
required: false
type: boolean
default: true
prerelease:
description: 'Prerelease?'
required: false
type: boolean
default: true
npm-version:
description: 'NPM version bump?'
required: false
type: choice
options:
- major
- minor
- patch
default: 'patch'

# schedule:
# - cron: '0 12 * * 2' # Runs every Tuesday at 12:00 PM (noon) ET
permissions:
contents: write

jobs:
cli-release:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.AUTOMATION_USER_TOKEN }}

- name: Set Git author
run: |
git config --global user.email "[email protected]"
git config --global user.name "DevCycle Automation"
- name: Get node version
id: get_node_version
run: |
echo "NVMRC=$(cat .nvmrc)" >> $GITHUB_OUTPUT
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "${{ steps.get_node_version.outputs.NVMRC }}"

- name: Install dependencies
run: yarn install

- name: Build
run: yarn build

- name: Bump CLI version
run: npm version ${{ inputs.npm-version }} --force

- name: Get latest tag
run: echo "LATEST_TAG=$(git describe --abbrev=0 --tags)" >> $GITHUB_ENV

- name: Commit and push tag to main branch
run: |
git add .
git commit --amend -m "Release $LATEST_TAG"
git tag -f $LATEST_TAG
git push --atomic origin main $LATEST_TAG
- name: Release
uses: ./.github/actions/release
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# cannot read $LATEST_TAG here so using ${{ env.LATEST_TAG }}
release-tag: ${{ env.LATEST_TAG }}
draft: ${{ inputs.draft-release }}
prerelease: ${{ inputs.prerelease }}

- name: Update Doc
uses: ./.github/actions/update-doc
with:
latest_tag: $LATEST_TAG
access_token: ${{ secrets.AUTOMATION_USER_TOKEN }}
22 changes: 0 additions & 22 deletions .github/workflows/release.yml

This file was deleted.

46 changes: 0 additions & 46 deletions .github/workflows/tag.yml

This file was deleted.

49 changes: 0 additions & 49 deletions .github/workflows/update_doc.yml

This file was deleted.

0 comments on commit dfef810

Please sign in to comment.