|
| 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