Skip to content

Commit

Permalink
feat: Add feature to publish dynamic package from pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
cnavarro-prestashop committed Dec 12, 2023
1 parent 371e295 commit d391834
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 81 deletions.
80 changes: 0 additions & 80 deletions .github/actions/build-and-publish/action.yml

This file was deleted.

102 changes: 102 additions & 0 deletions .github/workflows/cd-publish-feature-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Publish package

on:
pull_request:
types: [opened, reopened, synchronize, labeled]

jobs:
define-packages:
runs-on: ubuntu-latest
name: define packages to build
if: ${{ github.event.label.name == 'build-package' }}
steps:
- name: Generate packages Matrix
id: set-packages
shell: bash
run: |
packages+=(
"components"
"locale"
"puik"
"resolver"
"tailwind-preset"
"theme"
"utils"
)
json=$(jq --compact-output --null-input '$ARGS.positional' --args -- "${packages[@]}")
echo packages="{\"packages\":$json}" >> $GITHUB_OUTPUT
outputs:
packages: '${{ steps.set-packages.outputs.packages }}'

publish-github-packages:
name: Publish package ${{ matrix.package }}
runs-on: ubuntu-latest
needs:
- define-packages

if: ${{ github.event.label.name == 'build-package' }}

permissions:
contents: read
packages: write

strategy:
matrix:
package: '${{ fromJSON(needs.define-packages.outputs.packages).packages }}'
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Get prefix
id: get_prefix
run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF#refs/heads/} | cut -d'/' -f2)" >> "$GITHUB_OUTPUT"

- name: Complete full package name to edit
id: get_full_package_name
shell: bash
run: |
if [[ "$PACKAGE" == 'puik' ]]; then
echo "package=puik" >> $GITHUB_OUTPUT
else
echo "package=puik-$PACKAGE" >> $GITHUB_OUTPUT
fi
env:
PACKAGE: ${{ matrix.package }}
- name: Modify name of the package.json locally
uses: maxgfr/github-change-json@main
with:
key: 'name'
value: '@prestashopcorp/${{ steps.get_full_package_name.outputs.package }}-${{ steps.get_prefix.outputs.BRANCH_NAME }}'
path: ./packages/${{ matrix.package }}/package.json

- name: Display new package.json
shell: bash
run: cat ./packages/${{ matrix.package }}/package.json

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8.x.x

- name: Setup node env πŸ—
uses: actions/setup-node@v3
with:
node-version: lts/hydrogen
registry-url: https://registry.npmjs.org/
cache: 'pnpm'

- name: Install dependencies πŸ‘¨πŸ»β€πŸ’»
run: pnpm i --frozen-lockfile

- name: Build
run: pnpm build

- name: Display new package.json
shell: bash
run: cat ./packages/${{ matrix.package }}/package.json

- name: Publish
run: npm publish --no-git-checks
working-directory: ./packages/${{ matrix.package }}/dist
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/cd-publish-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
with:
node-version: lts/hydrogen
registry-url: https://registry.npmjs.org/
cache: "pnpm"
cache: 'pnpm'

- name: Install dependencies πŸ‘¨πŸ»β€πŸ’»
run: pnpm i --frozen-lockfile
Expand Down

0 comments on commit d391834

Please sign in to comment.