Skip to content

Commit

Permalink
refactor: move preview-publish-package-01 to composite action
Browse files Browse the repository at this point in the history
  • Loading branch information
sbsrnt committed Mar 8, 2024
1 parent 9ea4657 commit b490874
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -1,79 +0,0 @@
name: Preview publish package - 01
run-name: Preview publish package - 01 - Publish pre-release

on:
workflow_call:
inputs:
GH_TOKEN:
required: true
type: string
GH_ACTOR:
required: true
type: string
prRef:
required: true
type: string

jobs:
publish-prerelease:
name: Publish pre-release
runs-on: ubuntu-latest
outputs:
changelog: ${{ steps.lerna_prerelease.outputs.changelog }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ inputs.GH_TOKEN }}
fetch-depth: 0
ref: ${{ inputs.prRef }}

- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm

- name: Configure Git
run: |
git config --global user.name "${{ inputs.GH_ACTOR }}"
git config --global user.email "${{ inputs.GH_ACTOR }}@users.noreply.github.com"
- name: GitHub Package Registry Identity
env:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
run: |
echo "//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN" > .npmrc
echo "@exile-watch:registry=https://npm.pkg.github.com/" >> .npmrc
- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Lerna publish pre-release
id: publish-prerelease
env:
CI: true
GH_TOKEN: ${{ inputs.GH_TOKEN }}
run: |
npx lerna version prerelease --preid preview --yes --no-push
npx lerna publish from-git --dist-tag next --yes
echo "changelog=$(npx lerna changed --json | tr '\n' ' ')" >> $GITHUB_OUTPUT
create-prerelease-changelog-artifact:
name: Create changelog artifact
needs: publish-prerelease
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Write changelog to a file
run: echo "${{ needs.publish-prerelease.outputs.changelog }}" >> changelog.txt

- name: Upload changelog as an artifact
uses: actions/upload-artifact@v4
with:
name: changelog-artifact
path: changelog.txt
retention-days: 1
74 changes: 74 additions & 0 deletions preview-publish-package/01-publish-prerelease/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Preview publish package - 01 - Publish pre-release
description: Creates prerelease in x.x.x-preview.x format and publishes to github registry

inputs:
GH_TOKEN:
description: A GitHub PAT
required: true
GH_ACTOR:
description: A GitHub username
required: true
prRef:
description: Pull request reference, e.g. `github.event.pull_request.head.ref`
required: true

outputs:
changelog:
description: `lerna changed --json` output # read: https://github.com/lerna/lerna/tree/main/libs/commands/changed#readme
value: ${{ steps.lerna_prerelease.outputs.changelog }}

runs:
using: composite
steps:
- uses: actions/checkout@v4
with:
token: ${{ inputs.GH_TOKEN }}
fetch-depth: 0
ref: ${{ inputs.prRef }}

- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm

- name: Configure Git
run: |
git config --global user.name "${{ inputs.GH_ACTOR }}"
git config --global user.email "${{ inputs.GH_ACTOR }}@users.noreply.github.com"
- name: GitHub Package Registry Identity
env:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
run: |
echo "//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN" > .npmrc
echo "@exile-watch:registry=https://npm.pkg.github.com/" >> .npmrc
- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Lerna publish pre-release
id: publish-prerelease
env:
CI: true
GH_TOKEN: ${{ inputs.GH_TOKEN }}
run: |
npx lerna version prerelease --preid preview --yes --no-push
npx lerna publish from-git --dist-tag next --yes
echo "changelog=$(npx lerna changed --json | tr '\n' ' ')" >> $GITHUB_OUTPUT
- name: Write changelog to a file
id: create-changelog-artifact
if: steps.publish-prerelease.outcome == 'success'
run: echo "${{ needs.publish-prerelease.outputs.changelog }}" >> changelog.txt
shell: bash

- name: Upload changelog as an artifact
if: steps.create-changelog-artifact.outcome == 'success'
uses: actions/upload-artifact@v4
with:
name: changelog-artifact
path: changelog.txt
retention-days: 1
2 changes: 1 addition & 1 deletion preview-publish-package/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ runs:

- id: CI-01
if: steps.CI-00.outcome == 'success'
uses: ./.github/workflows/preview-publish-package-01-publish-prerelease.yml
uses: exile-watch/doryani/preview-publish-package/01-publish-prerelease@main
with:
GH_ACTOR: ${{ inputs.GH_ACTOR }}
GH_TOKEN: ${{ inputs.GH_TOKEN }}
Expand Down

0 comments on commit b490874

Please sign in to comment.