Skip to content

Commit

Permalink
ci: add preview package code (disabled) (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdehaven authored Jun 12, 2023
1 parent 0f303bf commit 957cfb1
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 1 deletion.
58 changes: 58 additions & 0 deletions .github/workflows/pr-closed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: On closing PR
on:
pull_request_target:
types:
- closed

jobs:
unpublish:
name: Unpublish or Deprecate NPM previews for PR
runs-on: ubuntu-latest
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN_PRIVATE_PUBLISH }}
steps:
- name: Checkout Source Code
uses: actions/checkout@v3

- 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 }}

- name: Create .npmrc
# Reference the env variable NPM_TOKEN here, not the secret
run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc

- name: Unpublish
run: |
toUnpublish=()
prNumber="${{github.event.number}}"
pkgName="@kong/design-system"
npm dist-tag rm "${pkgName}" "pr-${prNumber}" || true
for pkgVersion in $(npm view ${pkgName} --json|jq -r .versions|grep "\-pr.${prNumber}."|sed 's/,//'| sed 's/\"//g')
do
toUnpublish+=("${pkgName}@${pkgVersion}")
done
echo "List: ${toUnpublish[*]}"|sed 's/ /\n/g'
for (( i=${#toUnpublish[@]}-1; i>=0; i-- ))
do
echo ""
echo "*** deprecating: ${toUnpublish[i]}"
npm deprecate --force "${toUnpublish[i]}" "Deprecated PR preview" || true
done
for (( i=${#toUnpublish[@]}-1; i>=0; i-- ))
do
echo ""
echo "unpublishing: ${toUnpublish[i]}"
npm unpublish --force "${toUnpublish[i]}" || true
done
1 change: 0 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
- beta

jobs:
run-tests:
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,18 @@ jobs:
name: Run Tests
runs-on: ubuntu-latest
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@v3
with:
fetch-depth: 0

- name: Use Node.js
uses: actions/setup-node@v3
Expand All @@ -32,3 +42,56 @@ jobs:

- name: Build style dictionary
run: yarn build

# - name: Publish Previews
# if: github.event_name == 'pull_request'
# run: |
# git config user.email "konnectx-engineers+kongponents-bot@konghq.com"
# 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}"

# git checkout ${{ github.head_ref }}

# echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN_PRIVATE_PUBLISH }}" > .npmrc

# yarn version --prerelease --preid ${preid} --allow-branch ${{ github.head_ref }} --no-git-tag-version --yes --amend

# package_version=$(jq -r ".version" package.json)
# package=@kong/design-system@"${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=$(npm 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_ENV
# echo -e "$npm_instructions" >> $GITHUB_ENV
# echo "EOF" >> $GITHUB_ENV

# - name: Provide preview link info
# if: ${{ env.npm_instructions != '' }}
# uses: marocchino/sticky-pull-request-comment@v2
# with:
# header: pr_preview_consumption
# message: |
# ## ***Preview*** package from this PR in consuming application
# In consuming application project install preview version of kongponents generated by this PR:
# ```
# ${{ env.npm_instructions }}
# ```
# GITHUB_TOKEN: ${{ secrets.KONGPONENTS_BOT_PAT }}

0 comments on commit 957cfb1

Please sign in to comment.