Skip to content

watch

watch #2383

Workflow file for this run

name: watch
env:
BASE_URL: "https://registry.k6.io"
on:
workflow_dispatch:
inputs:
force_changed:
description: Force "changed" state
type: boolean
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: "40 */2 * * *"
permissions:
actions: write
pages: write
id-token: write
contents: write
jobs:
generate:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
XDG_CACHE_HOME: ${{ github.workspace }}/build/cache
HTDOCS_DIR: ${{ github.workspace }}/build/htdocs
BUILD_DIR: ${{ github.workspace }}/build
outputs:
changed: ${{ steps.generate.outputs.changed }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Prepare
run: |
mkdir -p ${{ env.HTDOCS_DIR }}
cp -rp public/* ${{ env.HTDOCS_DIR }}
cp -p registry.schema.* ${{ env.HTDOCS_DIR }}
cp -p openapi.yaml ${{ env.HTDOCS_DIR }}
mkdir -p ${{ env.XDG_CACHE_HOME }}
- name: Cache Restore
uses: actions/cache/restore@v4
with:
path: ${{ env.XDG_CACHE_HOME }}
key: xdg-cache
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22.x"
- name: Setup eget
uses: grafana/k6-extension-actions/[email protected]
- name: Setup k6registry
uses: grafana/k6-extension-actions/[email protected]
- name: Run k6registry
id: generate
env:
GITHUB_TOKEN: ${{github.token}}
run: >
k6registry -v
--lint
--api "${{ env.HTDOCS_DIR }}"
--ref "${{ env.BASE_URL }}/registry.json"
--test /registry.json,/catalog.json,/product/oss.json,/product/oss-catalog.json
--test /tier/official.json,/tier/official-catalog.json,/tier/community.json,/tier/community-catalog.json
--test /tier/at-least/official.json,/tier/at-least/official-catalog.json,/tier/at-least/partner.json,/tier/at-least/partner-catalog.json
registry.yaml
- name: Cache Clean
if: ${{ ( github.ref_name == 'main' && steps.generate.outputs.changed == 'true' ) || inputs.force_changed }}
run: |
gh extension install actions/gh-actions-cache
if gh cache list --key xdg-cache | grep -q xdg-cache; then
gh actions-cache delete xdg-cache --confirm
fi
- name: Cache Save
uses: actions/cache/save@v4
if: ${{ ( github.ref_name == 'main' && steps.generate.outputs.changed == 'true' ) || inputs.force_changed }}
with:
path: ${{ env.XDG_CACHE_HOME }}
key: xdg-cache
- name: Upload Site
uses: actions/upload-artifact@v4
if: ${{ ( github.ref_name == 'main' && steps.generate.outputs.changed == 'true') || inputs.force_changed }}
with:
path: ${{ env.HTDOCS_DIR }}
name: "htdocs"
overwrite: true
publish:
runs-on: ubuntu-latest
needs:
- generate
if: ${{ ( github.ref_name == 'main' && needs.generate.outputs.changed == 'true' ) || inputs.force_changed }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HTDOCS_DIR: ${{ github.workspace }}/htdocs
steps:
- name: Download Site
uses: actions/download-artifact@v4
with:
path: ${{ env.HTDOCS_DIR }}
name: "htdocs"
- name: Configure Pages
uses: actions/configure-pages@v5
- name: Upload Pages Artifact
uses: actions/upload-pages-artifact@v3
with:
path: ${{ env.HTDOCS_DIR }}
- name: Deploy Pages
uses: actions/deploy-pages@v4
wiki:
runs-on: ubuntu-latest
needs:
- generate
if: ${{ ( github.ref_name == 'main' && needs.generate.outputs.changed == 'true' ) || inputs.force_changed }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HTDOCS_DIR: ${{ github.workspace }}/htdocs
WIKI_WORK_DIR: ${{ github.workspace }}/wiki.work
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout Wiki
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}.wiki
path: ${{ env.WIKI_WORK_DIR }}
- name: Download Site
uses: actions/download-artifact@v4
with:
path: ${{ env.HTDOCS_DIR }}
name: "htdocs"
- name: Setup gomplate
uses: jason-dour/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate
run: |
rm -rf ${{ env.WIKI_WORK_DIR }}/*
gomplate -c registry=${{ env.HTDOCS_DIR }}/registry.json -c metrics=${{ env.HTDOCS_DIR }}/metrics.json -c official_metrics=${{ env.HTDOCS_DIR }}/tier/official-metrics.json -c schema=registry.schema.json --input-dir wiki --output-map='${{env.WIKI_WORK_DIR}}/{{.in|strings.TrimSuffix ".tpl"}}'
- name: Push
run: |
cd ${{env.WIKI_WORK_DIR}}
git config --local user.email 'github-actions[bot]@users.noreply.github.com'
git config --local user.name 'github-actions[bot]'
git add .
if git commit -m "Update due to registry changes" 2>/dev/null >/dev/null; then
git push
fi
notify:
strategy:
matrix:
repo:
- k6-extension-registry-wayback
- k6-extension-list
- k6-docs
- k6-distro-official
- k6-distro-cloud
- k6-distro-synthetic
runs-on: ubuntu-latest
env:
EVENT_TYPE: extension-registry-changed
needs:
- generate
- publish
if: ${{ ( github.ref_name == 'main' && needs.generate.outputs.changed == 'true' ) || inputs.force_changed }}
steps:
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.K6_EXTENSION_REGISTRY_CHANGE_NOTIFIER_ID }}
private-key: ${{ secrets.K6_EXTENSION_REGISTRY_CHANGE_NOTIFIER_PEM }}
owner: ${{ github.repository_owner }}
- name: Dispatch event
continue-on-error: true
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ steps.generate-token.outputs.token }}
repository: ${{ github.repository_owner }}/${{ matrix.repo }}
event-type: ${{ env.EVENT_TYPE }}