-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add feature to publish dynamic package from pull request
- Loading branch information
1 parent
371e295
commit 9b7f3b8
Showing
3 changed files
with
125 additions
and
81 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
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 }}' | ||
|
||
edit-package-name: | ||
name: Edit package name for ${{ 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 | ||
|
||
publish-github-packages: | ||
name: Publish on registry | ||
runs-on: ubuntu-latest | ||
|
||
needs: | ||
- define-packages | ||
- edit-package-name | ||
|
||
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: 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: Publish | ||
# run: pnpm publish --no-git-checks | ||
# working-directory: ./packages/${{ matrix.package }}/dist | ||
# env: | ||
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
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