Skip to content

Plugin Registry - PR check - Publish Registry Content #898

Plugin Registry - PR check - Publish Registry Content

Plugin Registry - PR check - Publish Registry Content #898

#
# Copyright (c) 2020-2021 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
name: Plugin Registry - PR check - Publish Registry Content
on:
workflow_run:
workflows: ["Plugin Registry - PR check - Build"]
types:
- completed
jobs:
publish:
# only if it's a pull request
if: github.event.workflow_run.event == 'pull_request'
name: publish
runs-on: ubuntu-22.04
steps:
- name: download dist artifact
uses: dawidd6/action-download-artifact@b59d8c6a6c5c6c6437954f470d963c0b20ea7415 #v2
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
name: plugin-registry-content-devspaces
path: content
- name: PR number
uses: dawidd6/action-download-artifact@b59d8c6a6c5c6c6437954f470d963c0b20ea7415 #v2
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
name: pull-request-number
- name: Grab pull request number
run: |
ls -la
pwd
pr_number=$(cat "PR_NUMBER")
if ! [[ "$pr_number" =~ ^[0-9]+$ ]]; then
echo "pr number invalid"
exit 1
fi
echo "PR_NUMBER=$pr_number" >> $GITHUB_ENV
- name: PR sha
uses: dawidd6/action-download-artifact@b59d8c6a6c5c6c6437954f470d963c0b20ea7415 #v2
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
name: pull-request-sha
- name: Grab pull request sha1
run: |
pr_sha=$(cat "PR_SHA")
echo "PR_SHA=$pr_sha" >> $GITHUB_ENV
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: publish
env:
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
run: |
sudo apt-get install tree
npm install -g surge
mkdir unpacked
tar zxvf content/*.tgz -C unpacked/
rm -rf ./unpacked/v3/resources/
# generate tree index on all directories
for directory in `find unpacked/ -type d`; do
(cd $directory && tree -H '.' -L 1 --noreport --charset utf-8 | sed '/<p class="VERSION">/,/<\/p>/d' > index.html)
done
# Make meta.yaml as index
for file in $(find unpacked -name 'meta.yaml' -type f); do
PARENT_DIR=$(dirname $file);
cp ${PARENT_DIR}/meta.yaml ${PARENT_DIR}/index.html
done
export DEPLOY_DOMAIN=https://pr-check-${PR_NUMBER}-devspaces-plugin-registry.surge.sh
echo "DEPLOY_DOMAIN=$DEPLOY_DOMAIN" >> $GITHUB_ENV
surge ./unpacked --domain $DEPLOY_DOMAIN
- name: 'Comment PR'
uses: actions/github-script@v6
with:
script: |
const { repo: { owner, repo } } = context;
await github.rest.repos.createCommitStatus({ owner, repo, sha: process.env.PR_SHA, state: "success", target_url: process.env.DEPLOY_DOMAIN, description: "Browse registry content live", context: "Surge" })