feat: Add feature to publish dynamic package from pull request #4
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 for every pull request containing label 'build-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 }}' | |
edit-package-name: | |
name: Edit every packages names to add the branch name as prefix | |
runs-on: ubuntu-latest | |
if: ${{ github.event.label.name == 'build-package' }} | |
permissions: | |
contents: read | |
packages: write | |
strategy: | |
matrix: | |
package: '${{ fromJSON(needs.define-packages.outputs.packages).packages }}' | |
steps: | |
- name: Get prefix | |
id: get_prefix | |
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | cut -d'/' -f2)" >> "$GITHUB_OUTPUT" | |
- name: Change package name for 'puik' package | |
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 | |
publish-github-packages: | |
name: Publish on registry | |
runs-on: ubuntu-latest | |
if: ${{ github.event.label.name == 'build-package' }} | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- 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: Publish | |
run: pnpm publish --no-git-checks | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |