Skip to content

Commit

Permalink
Use staging app name module for content changes table generation (git…
Browse files Browse the repository at this point in the history
…hub#21805)

* Use the 'script/deployment/create-staging-app-name' module when creating the content changes table comments

* Remove the shebang from the non-runnable script helper module
  • Loading branch information
JamesMGreene authored Sep 29, 2021
1 parent 3bdaf18 commit 12134aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
30 changes: 14 additions & 16 deletions .github/workflows/content-changes-table-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
filters: |
filterContentDir:
- 'content/**/*'
filterContentDir:
needs: PR-Preview-Links
if: ${{ needs.PR-Preview-Links.outputs.filterContentDir == 'true' }}
Expand All @@ -45,8 +46,10 @@ jobs:
node-version: 16.8.x
cache: npm

- name: Install dependencies
run: npm ci
- name: Install temporary dependencies
run: |
npm install --no-save github-slugger
npm install --no-save --include=optional esm
- name: Get changes table
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
Expand All @@ -55,14 +58,17 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const slugify = require('github-slugger').slug
// Workaround to allow us to load ESM files with `require(...)`
const esm = require('esm')
require = esm({})
const HEROKU_APPNAME_MAX_LENGTH = 30
const { default: createStagingAppName } = require('./script/deployment/create-staging-app-name')
const repoName = context.payload.repository.name
const branchName = context.payload.pull_request.head.ref
const prNumber = context.payload.number
const stagingPrefix = getStagingPrefix(repoName, prNumber, branchName)
const stagingPrefix = createStagingAppName({
repo: context.payload.repository.name,
pullNumber: context.payload.number,
branch: context.payload.pull_request.head.ref,
})
const response = await github.repos.compareCommits({
owner: context.repo.owner,
Expand Down Expand Up @@ -93,14 +99,6 @@ jobs:
markdownTable += markdownLine
}
function getStagingPrefix (prefix, prNumber, branch) {
// Added a - in front of prNumber
return `${prefix}-${prNumber}--${slugify(branch)}`
.toLowerCase()
.slice(0, HEROKU_APPNAME_MAX_LENGTH)
.replace(/_/g, '-')
.replace(/-+$/, '')
}
core.setOutput('changesTable', markdownTable)
- name: Find content directory changes comment
Expand Down
1 change: 0 additions & 1 deletion script/deployment/create-staging-app-name.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env node
import GithubSlugger from 'github-slugger'
const slugify = GithubSlugger.slug

Expand Down

0 comments on commit 12134aa

Please sign in to comment.