feat: Add feature to publish dynamic package from pull request #21
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |