Skip to content

Commit

Permalink
ci: add package previews
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdehaven committed Jun 5, 2024
1 parent 3a52a69 commit 13a0f79
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 2 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/cleanup-preview-packages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Cleanup PR preview packages
on:
workflow_dispatch:

schedule:
- cron: '0 2/6 * * 6,0'

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

jobs:
cleanup:
name: Cleanup PR Previews
runs-on: ubuntu-latest
timeout-minutes: 30
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN_PUBLIC_PUBLISH }}
GITHUB_TOKEN: ${{ secrets.KONGPONENTS_BOT_PAT }}

steps:
- name: Checkout Source Code
uses: actions/checkout@v4

- name: Prepare cleanup
id: prepare
run: |
echo "openPRs=$(gh pr list --state open --json number|jq -cM 'map(.number|tostring)')" >> $GITHUB_OUTPUT
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
- name: Cleanup PR preview
uses: Kong/public-shared-actions/pr-previews/cleanup@main
with:
package: "@kong/eslint-config-kong-ui"
openPRs: ${{ steps.prepare.outputs.openPRs }}
23 changes: 23 additions & 0 deletions .github/workflows/pr-closed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: On closing PR
on:
pull_request_target:
types:
- closed

jobs:
remove-pr-preview-comment:
name: Remove PR preview comment from PR
runs-on: ubuntu-latest
timeout-minutes: 5
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN_PUBLIC_PUBLISH }}
steps:
- name: Checkout Source Code
uses: actions/checkout@v4

- name: Remove preview consumption comment
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr_preview_consumption
delete: true
GITHUB_TOKEN: ${{ secrets.KONGPONENTS_BOT_PAT }}
64 changes: 64 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Remove preview consumption comment
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr_preview_consumption
delete: true
GITHUB_TOKEN: ${{ secrets.KONGPONENTS_BOT_PAT }}

- name: Checkout
uses: actions/checkout@v4
with:
Expand All @@ -34,3 +42,59 @@ jobs:

- name: Lint
run: pnpm lint

- name: Publish Package Preview
id: package-preview
# Do not run for `alpha` or `beta` branches
if: github.event_name == 'pull_request' && (github.actor != 'renovate[bot]' || contains(github.event.pull_request.labels.*.name, 'create preview package')) && !contains(github.head_ref || github.ref_name, 'alpha') && !contains(github.head_ref || github.ref_name, 'beta')
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN_PUBLIC_PUBLISH }}
run: |
git config user.email "[email protected]"
git config user.name "Kong UI Bot"
preid="pr.${{ github.event.pull_request.number }}.$(git rev-parse --short ${{ github.event.pull_request.head.sha }})"
tag="pr-${{ github.event.pull_request.number }}"
echo "preid=${preid}"
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
# Use yarn to bump the version for the prerelease
pnpm version prerelease --preid ${preid} --no-git-tag-version --yes --amend
package_version=$(jq -r ".version" package.json)
package=@kong/eslint-config-kong-ui@"${package_version}"
npm show "${package}" >/dev/null 2>&1 && npm_show_status=0 || npm_show_status=1
if [ $npm_show_status -eq 0 ]; then
echo "Package ${package} is already published. Skipping publishing."
exit 0
fi
npm_instructions=""
pkg=$(pnpm publish --no-git-checks --access public --report-summary --tag "${tag}" | grep "+ "| sed 's/+ //')
if [[ -z "${pkg}" ]]; then
echo "Error publishing package"
exit -1
fi
npm_instructions="@$(echo ${pkg}|cut -d'@' -f2)@${tag}"
echo "npm_instructions<<EOF" >> $GITHUB_OUTPUT
echo -e "$npm_instructions" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Provide preview link info
if: ${{ steps.package-preview.outputs.npm_instructions != '' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr_preview_consumption
message: |
### Install the preview package from this PR
```sh
${{ steps.package-preview.outputs.npm_instructions }}
```
GITHUB_TOKEN: ${{ secrets.KONGPONENTS_BOT_PAT }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# eslint-config-kong-ui
# @kong/eslint-config-kong-ui
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "eslint-config-kong-ui",
"name": "@kong/eslint-config-kong-ui",
"version": "1.0.0",
"description": "Sharable ESLint configuration for Kong's frontend repositories",
"main": "configs/index.mjs",
Expand Down

0 comments on commit 13a0f79

Please sign in to comment.