From f0303416f577e9ffc4f6dacd531767328ea691fa Mon Sep 17 00:00:00 2001 From: Sarah Schneider Date: Mon, 23 Nov 2020 17:03:02 -0500 Subject: [PATCH] use js to find the version substring from the label string --- .../enterprise-algolia-label.js | 24 +++++++++++++++++++ .../sync-single-english-algolia-index.yml | 7 +++--- 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100755 .github/actions-scripts/enterprise-algolia-label.js diff --git a/.github/actions-scripts/enterprise-algolia-label.js b/.github/actions-scripts/enterprise-algolia-label.js new file mode 100755 index 0000000000..bb8d8f8970 --- /dev/null +++ b/.github/actions-scripts/enterprise-algolia-label.js @@ -0,0 +1,24 @@ +#!/usr/bin/env node + +const fs = require('fs') +const core = require('@actions/core') +const eventPayload = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8')) + +// This workflow-run script: +// 1. Gets an array of labels on a PR +// 2. Finds one with the relevant Algolia text +// 3. Gets the version substring from the label string + +const labelText = 'sync-english-index-for-' +const labelsArray = eventPayload.pull_request.labels + +// Find the relevant label +const algoliaLabel = labelsArray.find(label => label.startsWith(labelText)) + +// Given: sync-english-index-for-enterprise-server@3.0 +// Returns: enterprise-server@3.0 +const versionToSync = algoliaLabel.split(labelText)[1] + +// Store the version so we can access it later in the workflow +core.setOutput('versionToSync', versionToSync) +process.exit(0) \ No newline at end of file diff --git a/.github/workflows/sync-single-english-algolia-index.yml b/.github/workflows/sync-single-english-algolia-index.yml index 41048aedd2..b89c1f481d 100644 --- a/.github/workflows/sync-single-english-algolia-index.yml +++ b/.github/workflows/sync-single-english-algolia-index.yml @@ -15,7 +15,7 @@ on: jobs: updateIndices: name: Update English index for single version based on a label's version - if: github.repository == 'github/docs-internal' && startsWith(github.event.label.name, 'sync-english-index-for-') + if: github.repository == 'github/docs-internal' && contains(github.event.pull_request.labels.*.name, 'sync-english-index-for-') runs-on: ubuntu-latest steps: - name: checkout @@ -34,11 +34,10 @@ jobs: run: npm ci - name: Get version from label id: getVersion - run: | - echo "::set-output name=version::$(github.event.label.name.split('sync-english-index-for-')[1])" + run: $GITHUB_WORKSPACE/.github/actions-scripts/enterprise-algolia-label.js - name: Sync English index for single version env: - VERSION: ${{ steps.getVersion.outputs.version }} + VERSION: ${{ steps.getVersion.outputs.versionToSync }} LANGUAGE: 'en' ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }} ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}