Skip to content

Commit 732a454

Browse files
Add self-hosted package publishing (#5)
## Motivation for the change, related issues We need to deploy JS packages to a public-but-self-hosted location so the Studio app can consume as dependencies. We expect this to continue until we are again publishing releases to the NPM repo. ## Implementation details Add a workflow for deploying self-hosted packages. ## Testing Instructions (or ideally a Blueprint) We cannot test by manually running a new workflow until a version of the workflow exists on the main branch. So we will have to commit this PR without testing the workflow and follow up with a PR to fix the workflow. We can the next PR like this: - Manually run the new workflow - SSH into our package server and confirm the packages are deployed as expected - Create a local node package - Add a dependency on one of the self-hosted packages that depends on another (the `@wp-playground/cli` package URL should be good) - `npm install` - Confirm installation worked by testing `npx cli server`
1 parent bd250db commit 732a454

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Release self-hosted packages
2+
3+
on:
4+
workflow_dispatch:
5+
# Require a version bump (patch, minor, major) and an optional dist tag
6+
inputs:
7+
should_bump_version:
8+
type: boolean
9+
description: 'Should bump version?'
10+
required: true
11+
default: true
12+
version_bump:
13+
description: 'Version bump (patch, minor, or major)'
14+
required: true
15+
default: 'patch'
16+
17+
jobs:
18+
release:
19+
# Only run this workflow from the trunk branch and when it's triggered by a Playground maintainer
20+
if: >
21+
github.ref == 'refs/heads/trunk' && (
22+
github.actor == 'adamziel' ||
23+
github.actor == 'dmsnell' ||
24+
github.actor == 'bgrgicak' ||
25+
github.actor == 'brandonpayton' ||
26+
github.actor == 'zaerl'
27+
)
28+
29+
# Specify runner + deployment step
30+
runs-on: ubuntu-latest
31+
environment:
32+
name: self-hosted-packages
33+
steps:
34+
- name: Install dependencies
35+
run: apt-get install sshpass
36+
- uses: actions/checkout@v4
37+
with:
38+
ref: ${{ github.event.pull_request.head.ref }}
39+
clean: true
40+
persist-credentials: false
41+
submodules: true
42+
- name: Config git user
43+
run: |
44+
git config --global user.name "deployment_bot"
45+
git config --global user.email "[email protected]"
46+
git remote set-url origin https://${{ github.actor }}:${{ github.token }}@github.com/${{ github.repository }}
47+
- uses: ./.github/actions/prepare-playground
48+
# Version bump, release, tag a new version on GitHub
49+
- name: Bump package versions
50+
shell: bash
51+
if: inputs.should_bump_version == true
52+
run: npx [email protected] version ${{ inputs.version_bump || 'patch' }} --yes --no-private --loglevel=verbose
53+
- name: Set hosting base URL
54+
run: echo "HOSTING_BASE_URL='https://${{ vars.HOSTING_DOMAIN }}/${{ vars.HOSTING_SUBDIR }}'" >> $GITHUB_ENV
55+
- name: Build JS packages for self-hosting
56+
shell: bash
57+
run: npx nx run-many --all --target=package-for-self-hosting -- --hostingBaseUrl="$HOSTING_BASE_URL'
58+
- name: Set up deployment environment vars
59+
run: |
60+
export LATEST_PACKAGE_VERSION=$(cat packages/php-wasm/universal/package.json | jq -r '.version')
61+
echo "LATEST_PACKAGE_VERSION=$LATEST_PACKAGE_VERSION" >> $GITHUB_ENV
62+
echo "PACKAGE_SOURCE_DIR=dist/packages-for-self-hosting/$(echo "$HOSTING_BASE_URL" | jq -r @uri)" >> $GITHUB_ENV
63+
echo 'PACKAGE_TARGET_DIR=/srv/htdocs/${{ vars.HOSTING_SUBDIR }}' >> $GITHUB_ENV
64+
- name: Build source tarball
65+
run: tools/scripts/package-source.sh "v$LATEST_PACKAGE_VERSION" "$PACKAGE_SOURCE_DIR/playground-sources-${LATEST_PACKAGE_VERSION}.tar.gz"
66+
- name: Deploy self-hosted packages
67+
env:
68+
SSH_PASSPHRASE: '${{ secrets.TARGET_SSH_PASSPHRASE }}'
69+
run: |
70+
mkdir -p ~/.ssh
71+
echo "${{ secrets.TARGET_SSH_HOST_KEY }}" >> ~/.ssh/known_hosts
72+
chmod 0600 ~/.ssh/*
73+
sshpass -p "$TARGET_SSH_PASSPHRASE" ssh \
74+
${{ secrets.TARGET_SSH_USER }}@${{ secrets.TARGET_SSH_HOST }} \
75+
-tt -C "mkdir -p '$PACKAGE_TARGET_DIR'"
76+
rsync -avz -e "sshpass -p "$TARGET_SSH_PASSPHRASE" ssh" --delete \
77+
"dist/packages-for-self-hosting/" \
78+
"${{ secrets.TARGET_SSH_USER }}@${{ secrets.TARGET_SSH_HOST }}:$PACKAGE_TARGET_DIR"

0 commit comments

Comments
 (0)