Skip to content

Plugin Registry - GH Pages - Publish Registry Content #1242

Plugin Registry - GH Pages - Publish Registry Content

Plugin Registry - GH Pages - Publish Registry Content #1242

#
# Copyright (c) 2022 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 - GH Pages - Publish Registry Content
on:
push:
branches:
- 'devspaces-[0-9].[0-9]+-rhel-8'
- devspaces-3-rhel-8
paths:
- 'dependencies/che-plugin-registry/**'
# allow manual trigger of action in case things are stale
workflow_dispatch:
inputs:
TAG:
description: 'The tag to publish, eg., next or 3.y'
required: true
default: 'next'
# rebuild GH pages every night at 10pm
schedule:
- cron: "0 22 * * *"
jobs:
publish:
name: publish
runs-on: ubuntu-20.04
steps:
- name: Set defaults (for use in crontab or workflow_dispatch)
id: SETUP_TAG
shell: bash
env:
DEFAULT_TAG: 'next'
run: |
if [[ "$GITHUB_REF_NAME" ]]; then
if [[ "$GITHUB_REF_NAME" =~ devspaces-([0-9]+\.[0-9]+)-rhel-8 ]]; then
# just use the 3.2 part of devspaces-3.2-rhel-8
echo "TAG=${BASH_REMATCH[1]}" >> $GITHUB_ENV
elif [[ "$GITHUB_REF_NAME" =~ devspaces-([0-9]+)-rhel-8 ]]; then
# for devspaces-3-rhel-8, use next
echo "TAG=next" >> $GITHUB_ENV
else
echo "TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV
fi
else
echo "TAG=${{ github.event.inputs.TAG || env.DEFAULT_TAG }}" >> $GITHUB_ENV
fi
- name: Clone source code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: extract content
run: |
export BUILD_DIR="$PWD/content"
mkdir -p /tmp/devspaces-plugin-registry
touch /tmp/devspaces-plugin-registry/architectures.json
if [[ ${{ env.TAG }} =~ 3\.[0-9]+ ]]; then
version="${{ env.TAG }}"
elif [[ "$GITHUB_REF_NAME" == "devspaces-3-rhel-8" ]] || [[ ${{ env.TAG }} == "next" ]]; then
version="next"
else
version=$(cat dependencies/VERSION)
fi
# get arches and swap amd64 -> x86_64 so we have the uname -m value, not the quay arch name
docker manifest inspect quay.io/devspaces/pluginregistry-rhel8:"$version" | jq -r '.manifests[] | .platform.architecture' | sed -r -e "s#amd64#x86_64#g" \
> /tmp/devspaces-plugin-registry/architectures.json
for arch in $(cat /tmp/devspaces-plugin-registry/architectures.json); do
docker pull quay.io/devspaces/pluginregistry-rhel8:"$version" --platform="$arch"
docker create --platform linux/"$arch" --name pluginRegistry quay.io/devspaces/pluginregistry-rhel8:"$version" sh
mkdir -p "$BUILD_DIR"/"$arch"/v3
docker cp pluginRegistry:/var/www/html/v3 "$BUILD_DIR"/"$arch"
docker rm -f pluginRegistry
cp "$BUILD_DIR"/"$arch"/v3/plugins/index.json "$BUILD_DIR"/"$arch"/index.json
done
- name: Publish to gh-pages
env:
GITHUB_TOKEN: ${{ secrets.CRW_BUILD_TOKEN }}
run: |
export BUILD_DIR="$PWD/content"
export GH_PAGES_DIR="$PWD/gh-pages"
export GITHUB_TOKEN=${{ secrets.CRW_BUILD_TOKEN }}
GITHUB_REPO_NAME="devspaces"
VERSION_DIR="che-plugin-registry"/"$(cat dependencies/VERSION)"
rm "$GH_PAGES_DIR" -rf;
mkdir "$GH_PAGES_DIR"
cd "$GH_PAGES_DIR"
rm -rf che-plugin-registry
git clone -b gh-pages "https://github.com/$GITHUB_REPOSITORY.git"
cd "$GITHUB_REPO_NAME"
for arch in $(cat /tmp/devspaces-plugin-registry/architectures.json); do
TARGET_DIR="$VERSION_DIR"/"$arch"
echo "Delete and recreate $TARGET_DIR ..."
[ -d "$TARGET_DIR" ] && git rm -q -r "$TARGET_DIR"
[ ! -d "$VERSION_DIR" ] && mkdir -p "$VERSION_DIR"
rm -rf "$BUILD_DIR"/"$arch"/v3/resources
cp -r "$BUILD_DIR"/"$arch" "$TARGET_DIR"
done
# Check if the branch is devspaces-3-rhel-8 = next
if [[ "$GITHUB_REF_NAME" == "devspaces-3-rhel-8" ]]; then
NEXT_VERSION_DIR="che-plugin-registry/next"
echo "Delete and recreate $NEXT_VERSION_DIR ..."
[ -d "$NEXT_VERSION_DIR" ] && git rm -q -r "$NEXT_VERSION_DIR"
mkdir -p "$NEXT_VERSION_DIR"
cp -r "$BUILD_DIR"/. "$NEXT_VERSION_DIR"
fi
# Make meta.yaml as index
while IFS= read -r -d '' file
do
PARENT_DIR=$(dirname "$file");
cp "${PARENT_DIR}"/meta.yaml "${PARENT_DIR}"/index.json;
done < <(find . -name 'meta.yaml' -type f -print0)
git add "$VERSION_DIR"
[ -n "$NEXT_VERSION_DIR" ] && git add "$NEXT_VERSION_DIR"
git config user.email "[email protected]"
git config user.name "devstudio-release"
git config --global push.default matching
git config --global pull.rebase true
git config --global hub.protocol https
git remote set-url origin https://$GITHUB_TOKEN:[email protected]/redhat-developer/devspaces.git
git diff-index --quiet HEAD || git commit -m "publish registry $VERSION - $(date)" -s || echo "Nothing to commit!"
git push origin gh-pages || echo "No changes to push!" # https://redhat-developer.github.io/devspaces/
for arch in $(cat /tmp/devspaces-plugin-registry/architectures.json); do
echo "Plugin registry published to https://redhat-developer.github.io/$GITHUB_REPO_NAME/$VERSION_DIR/$arch/v3/plugins/"
if [[ -n "$NEXT_VERSION_DIR" ]]; then
echo "Plugin registry published to https://redhat-developer.github.io/$GITHUB_REPO_NAME/$NEXT_VERSION_DIR/$arch/v3/plugins/"
fi
done
- name: Trigger rebuild of devfile registry
env:
GITHUB_TOKEN: ${{ secrets.CRW_BUILD_TOKEN }}
run: |
export GITHUB_TOKEN=${{ secrets.CRW_BUILD_TOKEN }}
git clone -b "$GITHUB_REF_NAME" "https://github.com/$GITHUB_REPOSITORY.git" ds
cd ds
git config user.email "[email protected]"
git config user.name "devstudio-release"
git config --global push.default matching
git config --global pull.rebase true
git config --global hub.protocol https
git remote set-url origin https://$GITHUB_TOKEN:[email protected]/redhat-developer/devspaces.git
sed -i -r -e "s@^Webhook triggered on: .+@Webhook triggered on: $(date) [pluginregistry GH page]@" dependencies/che-devfile-registry/webhook_trigger.txt
git commit -m "chore: update webhook_trigger.txt for pluginregistry GH page @ $GITHUB_REF_NAME" dependencies/che-devfile-registry/webhook_trigger.txt
git push origin "$GITHUB_REF_NAME"