Skip to content
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

liuliu/debug-publish #290

Closed
wants to merge 9 commits into from
Closed
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
168 changes: 168 additions & 0 deletions .github/workflows/dry-run-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: Publish Package - Dry Run

on:
workflow_dispatch:
inputs:
package:
description: 'Name of package to publish'
required: true
default: 'components'
type: choice
options:
- components
- contexts
- hooks
- resource-utils
- utils
version:
description: 'SemVer format release tag, i.e. 0.2.4'
required: true
dry_run:
description: 'Simulate publishing (no real changes)'
required: true
default: true
type: boolean

concurrency:
group: ${{ github.workflow }}-${{ github.event.inputs.package }}-${{ github.ref }}
cancel-in-progress: true

jobs:
format-version:
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.format_version.outputs.version }}
steps:
- name: Format Input
id: format_version
run: |
version="${{ github.event.inputs.version }}"
if [[ $version == v* ]];
then
version="${version:1}"
fi
echo "version=$version" >> $GITHUB_OUTPUT

build-and-release:
needs: format-version
name: Create release
runs-on: ubuntu-22.04
outputs:
release_id: ${{ steps.create_release.outputs.id }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Update version command
run: |
sed -i -e 's/"version"\s*:\s*".*"/"version": "'"$NEW_VERSION"'"/' "$FILE"
env:
FILE: ${{ github.workspace }}/packages/${{ github.event.inputs.package }}/package.json
NEW_VERSION: ${{ github.event.inputs.version }}

- name: Determine and Set Tags
run: |
# Find the last two tags that match the package pattern, sort them to get the latest
TAGS=$(git tag | grep "^${{ github.event.inputs.package }}-v" | sort -rV | head -n 1)
LAST_TAG=$(echo "$TAGS" | sed -n '1p')
echo "LAST_TAG=${LAST_TAG}" >> $GITHUB_ENV

- name: Generate Changelog
id: changelog
uses: mikepenz/release-changelog-builder-action@v4
with:
configurationJson: |
{
"categories": [
{
"title": "## ${{ github.event.inputs.package }}",
"labels": [
"${{ github.event.inputs.package }}"
],
"exhaustive": true,
"exhaustive_rules": "false",
"empty_content": "- no matching PRs",
"rules": [
{
"pattern": "${{ github.event.inputs.package }}",
"on_property": "labels"
},
{
"pattern": "merged",
"on_property": "status"
}
]
}
],
"sort": {
"order": "ASC",
"on_property": "mergedAt"
},
"template": "#{{CHANGELOG}}\n",
"pr_template": "* [#{{NUMBER}}](#{{URL}}): #{{TITLE}}\n #{{BODY}}",
"empty_template": "- no changes",
"max_tags_to_fetch": 200,
"max_back_track_time_days": 365,
"base_branches": [
"main"
]
}
fromTag: "${{ env.LAST_TAG }}"
toTag: "main"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Add and Commit Changes
uses: EndBug/[email protected]
with:
message: "Update ${{ github.event.inputs.package }} package version to ${{ needs.format-version.outputs.version }}"
add: "${{ github.workspace }}/packages/${{ github.event.inputs.package }}/package.json"
cwd: "."
new_branch: ${{ github.event.inputs.package }}-package-release

- name: Create Pull Request
run: gh pr create --base main --head "${{ github.event.inputs.package }}-package-release" --title "Release ${{ github.event.inputs.package }} ${{ needs.format-version.outputs.version }}" --body "Created by the Release workflow to update ${{ github.event.inputs.package }} version"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Enable Pull Request Auto-Merge
run: gh pr merge --merge --auto "${{ github.event.inputs.package }}-package-release"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Enable Corepack before setting up Node
run: corepack enable

- uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'

- name: Install and run build
working-directory: ./
run: |
yarn install --immutable
yarn dbuild

- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.inputs.package }}-v${{ needs.format-version.outputs.version }}
release_name: ${{ github.event.inputs.package }}-v${{ needs.format-version.outputs.version }}

- name: Publish to npm
if: ${{ !inputs.dry_run }} # Only run if dry_run is FALSE
run: npm publish
working-directory: packages/${{ github.event.inputs.package }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Simulate Publish (Dry Run)
if: ${{ inputs.dry_run }}
run: npm publish --dry-run # Simulate publishing
working-directory: packages/${{ github.event.inputs.package }}
171 changes: 171 additions & 0 deletions .github/workflows/publish-dry-run.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
name: Publish Package - Dry Run

on:
workflow_dispatch:
inputs:
package:
description: 'Name of package to publish'
required: true
default: 'components'
type: choice
options:
- components
- contexts
- hooks
- resource-utils
- utils
version:
description: 'SemVer format release tag, i.e. 0.2.4'
required: true
dry_run:
description: 'Simulate publishing (no real changes)'
required: true
default: true
type: boolean
push:
branches:
- liuliu/debug-publish

concurrency:
group: ${{ github.workflow }}-${{ github.event.inputs.package }}-${{ github.ref }}
cancel-in-progress: true

jobs:
format-version:
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.format_version.outputs.version }}
steps:
- name: Format Input
id: format_version
run: |
version="${{ github.event.inputs.version }}"
if [[ $version == v* ]];
then
version="${version:1}"
fi
echo "version=$version" >> $GITHUB_OUTPUT

build-and-release:
needs: format-version
name: Create release
runs-on: ubuntu-22.04
outputs:
release_id: ${{ steps.create_release.outputs.id }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Update version command
run: |
sed -i -e 's/"version"\s*:\s*".*"/"version": "'"$NEW_VERSION"'"/' "$FILE"
env:
FILE: ${{ github.workspace }}/packages/${{ github.event.inputs.package }}/package.json
NEW_VERSION: ${{ github.event.inputs.version }}

- name: Determine and Set Tags
run: |
# Find the last two tags that match the package pattern, sort them to get the latest
TAGS=$(git tag | grep "^${{ github.event.inputs.package }}-v" | sort -rV | head -n 1)
LAST_TAG=$(echo "$TAGS" | sed -n '1p')
echo "LAST_TAG=${LAST_TAG}" >> $GITHUB_ENV

- name: Generate Changelog
id: changelog
uses: mikepenz/release-changelog-builder-action@v4
with:
configurationJson: |
{
"categories": [
{
"title": "## ${{ github.event.inputs.package }}",
"labels": [
"${{ github.event.inputs.package }}"
],
"exhaustive": true,
"exhaustive_rules": "false",
"empty_content": "- no matching PRs",
"rules": [
{
"pattern": "${{ github.event.inputs.package }}",
"on_property": "labels"
},
{
"pattern": "merged",
"on_property": "status"
}
]
}
],
"sort": {
"order": "ASC",
"on_property": "mergedAt"
},
"template": "#{{CHANGELOG}}\n",
"pr_template": "* [#{{NUMBER}}](#{{URL}}): #{{TITLE}}\n #{{BODY}}",
"empty_template": "- no changes",
"max_tags_to_fetch": 200,
"max_back_track_time_days": 365,
"base_branches": [
"main"
]
}
fromTag: "${{ env.LAST_TAG }}"
toTag: "main"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Add and Commit Changes
uses: EndBug/[email protected]
with:
message: "Update ${{ github.event.inputs.package }} package version to ${{ needs.format-version.outputs.version }}"
add: "${{ github.workspace }}/packages/${{ github.event.inputs.package }}/package.json"
cwd: "."
new_branch: ${{ github.event.inputs.package }}-package-release

- name: Create Pull Request
run: gh pr create --base main --head "${{ github.event.inputs.package }}-package-release" --title "Release ${{ github.event.inputs.package }} ${{ needs.format-version.outputs.version }}" --body "Created by the Release workflow to update ${{ github.event.inputs.package }} version"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Enable Pull Request Auto-Merge
run: gh pr merge --merge --auto "${{ github.event.inputs.package }}-package-release"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Enable Corepack before setting up Node
run: corepack enable

- uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'

- name: Install and run build
working-directory: ./
run: |
yarn install --immutable
yarn dbuild

- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.inputs.package }}-v${{ needs.format-version.outputs.version }}
release_name: ${{ github.event.inputs.package }}-v${{ needs.format-version.outputs.version }}

- name: Publish to npm
if: ${{ !github.event.inputs.dry_run }}
run: npm publish
working-directory: packages/${{ github.event.inputs.package }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Simulate Publish (Dry Run)
if: ${{ github.event.inputs.dry_run }}
run: npm publish --dry-run
working-directory: packages/${{ github.event.inputs.package }}
Loading
Loading