Skip to content

Commit

Permalink
[STRATCONN-4060] - Add slugs of destinations changed to release notes (
Browse files Browse the repository at this point in the history
…#2635)

* Test parsing slugs

* Remove comment

* Fix require

* one more try

* Consolidate release and publish jobs

* Update publish-test for testing

* Revert test setup

* Update comment
  • Loading branch information
varadarajan-tw authored Dec 11, 2024
1 parent 24983e8 commit 89cb1ef
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 23 deletions.
28 changes: 11 additions & 17 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
Expand All @@ -33,6 +36,11 @@ jobs:
registry-url: 'https://registry.npmjs.org'
cache: yarn

- name: Setup git credentials
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Install Dependencies
run: yarn install --frozen-lockfile

Expand All @@ -52,22 +60,6 @@ jobs:
run: |
yarn lerna publish from-package --yes --loglevel=verbose --dist-tag latest
release:
needs: build-and-publish # comment when testing locally with https://github.com/nektos/act

runs-on: ubuntu-20.04
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled to ensure the commit history for the repository is available to the action
fetch-tags: true

- name: Setup git credentials
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Generate Tags
id: get-release-tag
run: ./scripts/generate-release-tags.sh
Expand All @@ -79,5 +71,7 @@ jobs:
RELEASE_TAG: ${{ steps.get-release-tag.outputs.release-tag }}
with:
script: |
const cloudManifest = require('./packages/destination-actions/dist/destinations/index.js').manifest
const browserManifest = require('./packages/destinations-manifest/dist/index.js').manifest
const script = require('./scripts/github-action/create-github-release.js')
await script({github, context, core, exec})
await script({github, context, core, exec, cloudManifest, browserManifest})
49 changes: 43 additions & 6 deletions scripts/github-action/create-github-release.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This is a github action script and can be run only from github actions. To run this script locally, you need to mock the github object and context object.
module.exports = async ({ github, context, core, exec }) => {
module.exports = async ({ github, context, core, exec, cloudManifest, browserManifest }) => {
let { GITHUB_SHA, DRY_RUN, GITHUB_REF } = process.env

// Get the branch name from the GITHUB_REF
Expand Down Expand Up @@ -37,7 +37,21 @@ module.exports = async ({ github, context, core, exec }) => {
// Extract package tags that are published in the current release by lerna version
const packageTags = await extractPackageNames(GITHUB_SHA, exec, core)
const tagsContext = { currentRelease: newReleaseTag, prevRelease: latestReleaseTag, packageTags }
const changeLog = formatChangeLog(prs, tagsContext, context)
const cloudDestinationsByDirectory = Object.values(cloudManifest).reduce((acc, destination) => {
acc[destination.directory] = destination
return acc
}, {})
const browserDestinationsByDirectory = Object.values(browserManifest).reduce((acc, destination) => {
acc[destination.directory] = destination
return acc
}, {})
const changeLog = formatChangeLog(
prs,
tagsContext,
context,
cloudDestinationsByDirectory,
browserDestinationsByDirectory
)

// If DRY_RUN is set, then log the changelog and return
if (Boolean(DRY_RUN)) {
Expand Down Expand Up @@ -183,9 +197,11 @@ async function getPRsBetweenCommits(github, context, core, lastCommit, currentCo
}

// Format the changelog
function formatChangeLog(prs, tagsContext, context) {
function formatChangeLog(prs, tagsContext, context, cloudDestinationsByDir, browserDestinationsByDir) {
const { currentRelease, prevRelease, packageTags } = tagsContext
const prsWithAffectedDestinations = prs.map(mapPRWithAffectedDestinations)
const prsWithAffectedDestinations = prs.map((pr) =>
mapPRWithAffectedDestinations(pr, cloudDestinationsByDir, browserDestinationsByDir)
)
const internalPRS = prsWithAffectedDestinations.filter(
(pr) => pr.labels.includes('team:segment-core') || pr.labels.includes('team:segment')
)
Expand Down Expand Up @@ -218,6 +234,9 @@ function formatChangeLog(prs, tagsContext, context) {
}
]

// construct a set of unique affected slugs
const uniqueAffectedSlugs = new Set(prsWithAffectedDestinations.map((pr) => pr.affectedSlugs).flat())

// if there is no previous release, we simply print the current release
const releaseDiff = prevRelease ? `${prevRelease}...${currentRelease}` : currentRelease

Expand All @@ -228,6 +247,14 @@ function formatChangeLog(prs, tagsContext, context) {
https://github.com/${context.repo.owner}/${context.repo.repo}/compare/${releaseDiff}
<!-- DON'T DELETE THIS COMMENT
<affected-destinations>
${Array.from(uniqueAffectedSlugs)
.map((slug) => `${slug}`)
.join('\n')}
</affected-destinations>
-->
## Packages Published
${formattedPackageTags || 'No packages published'}
Expand All @@ -253,15 +280,20 @@ function formatTable(prs, tableConfig, title = '') {
/*
* Map PR with affected destinations
*/
function mapPRWithAffectedDestinations(pr) {
function mapPRWithAffectedDestinations(pr, cloudDestinationsByDirectory, browserDestinationsByDirectory) {
let affectedDestinations = []
let affectedSlugs = []
if (pr.labels.includes('mode:cloud')) {
pr.files
.filter((file) => file.includes('packages/destination-actions/src/destinations'))
.forEach((file) => {
const match = file.match(/packages\/destination-actions\/src\/destinations\/([^\/]+)\/*/)
if (match && !affectedDestinations.includes(match[1])) {
affectedDestinations.push(match[1])
// get the slug from the directory
if (cloudDestinationsByDirectory[match[1]]) {
affectedSlugs.push(cloudDestinationsByDirectory[match[1]].definition.slug)
}
}
})
}
Expand All @@ -272,12 +304,17 @@ function mapPRWithAffectedDestinations(pr) {
const match = file.match(/packages\/browser-destinations\/destinations\/([^\/]+)\/*/)
if (match && !affectedDestinations.includes(match[1])) {
affectedDestinations.push(match[1])
// get the slug from the directory
if (browserDestinationsByDirectory[match[1]]) {
affectedSlugs.push(browserDestinationsByDirectory[match[1]].definition.slug)
}
}
})
}
return {
...pr,
affectedDestinations: affectedDestinations.join(', ')
affectedDestinations: affectedDestinations.join(', '),
affectedSlugs: affectedSlugs
}
}

Expand Down

0 comments on commit 89cb1ef

Please sign in to comment.