Skip to content

Commit

Permalink
Merge pull request #129 from rees46/feat/composite
Browse files Browse the repository at this point in the history
feat: composites
  • Loading branch information
Nelfimov authored Apr 26, 2024
2 parents c34b6ba + 96b8d75 commit a660bdd
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/composite-action-start-js.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Composite start JS action
description: Prepare JS action - checkout, generate App token, yarn install

inputs:
nodeVersion:
description: Node version to run this workflow. Default 18 as it is in action cache
default: '18'
required: false
appId:
description: App ID for committing and pushing
required: true
appSecret:
description: App secret for committing changes
required: true

runs:
using: composite

steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ inputs.appId }}
private-key: ${{ inputs.appSecret }}
shell: bash

- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
ref: master
shell: bash

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.nodeVersion }}
shell: bash

- name: Install
run: yarn install --inline-builds
shell: bash
38 changes: 38 additions & 0 deletions .github/workflows/composite-base-commit-js.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Version composite action
description: patch versions of changed packages

inputs:
private:
description: Should apply only to private?
required: false
default: 'false'
checkChanges:
description: Should run 'yarn --since'?
required: false
default: 'true'
token:
description: GitHub PAT
required: true

outputs:
baseCommit:
description: Find last merge commits
value: ${{ steps.find_base_commit.outputs.baseCommit }}

runs:
using: composite

steps:
- name: Find Base Commit for master
id: find_base_commit
run: |
BASE_COMMIT=$(git log --merges -n 2 --format=format:%H | tail -n 1)
echo "baseCommit=$BASE_COMMIT" >> $GITHUB_OUTPUT
echo "Base Commit: $BASE_COMMIT"
shell: bash

- name: List changed workspaces
env:
BASE_COMMIT: ${{ steps.find_base_commit.outputs.baseCommit }}
run: yarn workspaces list --since=$BASE_COMMIT^
shell: bash
37 changes: 37 additions & 0 deletions .github/workflows/composite-publish-js.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Publish composite action
description: create changelog and publish if applicable

inputs:
onlyChangelog:
required: false
default: 'false'
description: Should only create changelog without publish
npmAuthToken:
required: false
description: NPM token for publishing
token:
required: true
description: GitHub PAT
baseCommit:
required: true
description: Base commit from which to parse workspace changes


runs:
using: composite

steps:
- name: Generate changelog
env:
GITHUB_TOKEN: ${{ inputs.token }}
BASE_COMMIT: ${{ inputs.baseCommit }}
run: yarn workspaces foreach --since=$BASE_COMMIT^ --verbose run changelog
shell: bash

- name: Publish
if: inputs.onlyChangelog == 'false'
env:
YARN_NPM_AUTH_TOKEN: ${{ inputs.npmAuthToken }}
BASE_COMMIT: ${{ inputs.baseCommit }}
run: yarn workspaces foreach --since=$BASE_COMMIT^ --verbose --topological --no-private npm publish --access public
shell: bash
34 changes: 34 additions & 0 deletions .github/workflows/composite-release-js.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Composite release JS action
description: Release action - create and publish release with source code

inputs:
isMonorepo:
required: false
default: 'false'
description: Treat this repo as monorepo. If true - tags for releases will include package names
baseCommit:
required: true
description: Base commit from which to parse changed workspaces
token:
required: true
description: GitHub PAT

runs:
using: composite

steps:
- name: Release monorepo
if: inputs.isMonorepo == 'true'
env:
BASE_COMMIT: ${{ inputs.baseCommit }}
GH_TOKEN: ${{ inputs.GITHUB_TOKEN }}
run: yarn workspaces foreach --since=$BASE_COMMIT^ exec 'bash -c "yarn pack && VERSION=$npm_package_version && NAME=$npm_package_name && gh release create \"\$NAME-v\$VERSION\" ./package.tgz --title=\$NAME-\$VERSION --notes-file=./CHANGELOG.md"'
shell: bash

- name: Release single package
if: inputs.isMonorepo == 'false'
env:
BASE_COMMIT: ${{ inputs.baseCommit }}
GH_TOKEN: ${{ inputs.GITHUB_TOKEN }}
run: yarn workspaces foreach --since=$BASE_COMMIT^ exec 'bash -c "yarn pack && VERSION=$npm_package_version && gh release create \"v\$VERSION\" ./package.tgz --title=\$VERSION --notes-file=./CHANGELOG.md"'
shell: bash
49 changes: 49 additions & 0 deletions .github/workflows/composite-version-js.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Version composite action
description: patch versions of changed packages

inputs:
private:
description: Should apply only to private?
required: false
default: 'false'
checkChanges:
description: Should run 'yarn --since'?
required: false
default: 'true'
token:
description: GitHub PAT
required: true

outputs:
committed:
description: Have the changes in version been committed?
value: ${{ jobs.run.outputs.committed }}

runs:
using: composite

steps:
- name: List changed workspaces
env:
BASE_COMMIT: ${{ steps.find_base_commit.outputs.baseCommit }}
run: yarn workspaces list --since=$BASE_COMMIT^
shell: bash

- name: Version
env:
GITHUB_TOKEN: ${{ inputs.token }}
IS_PRIVATE: ${{ inputs.private }}
SHOULD_CHECK_CHANGES: ${{ inputs.checkChanges }}
run: |
if [ $IS_PRIVATE == 'false' ]; then
PRIVATE_FLAG="--no-private"
fi
if [ $SHOULD_CHECK_CHANGES == 'true' ]; then
CHANGES_FLAG="--since=${{ steps.find_base_commit.outputs.baseCommit }}^"
else
CHANGES_FLAG="--all"
fi
yarn workspaces foreach $CHANGES_FLAG $PRIVATE_FLAG --verbose version patch --immediate
shell: bash

0 comments on commit a660bdd

Please sign in to comment.