Skip to content

Publish Registry Content #8229

Publish Registry Content

Publish Registry Content #8229

#
# 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: Publish Registry Content
on:
workflow_run:
workflows: ["Image Build PR check"]
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@v5
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
name: plugin-registry-content
path: content
- name: PR number
uses: dawidd6/action-download-artifact@v5
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
name: pull-request-number
- name: Grab pull request number
run: |
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@v5
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@v4
with:
node-version: '18'
- 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/
# 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 devfile.yaml as index
for file in $(find unpacked -name 'devfile.yaml' -type f)
do
PARENT_DIR=$(dirname $file);
cp ${PARENT_DIR}/devfile.yaml ${PARENT_DIR}/index.html
done
export DEPLOY_DOMAIN=https://pr-check-${PR_NUMBER}-che-plugin-registry.surge.sh
echo "DEPLOY_DOMAIN=$DEPLOY_DOMAIN" >> $GITHUB_ENV
surge ./unpacked --domain $DEPLOY_DOMAIN
- name: 'Comment PR'
uses: actions/github-script@v7
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"})