Skip to content

Commit

Permalink
ci(release): consolidate replace pkg version scripts (#2651)
Browse files Browse the repository at this point in the history
* ci(release): consolidate replace pkg version scripts

* chore: add console log to replace script
  • Loading branch information
bernardobridge authored Apr 15, 2024
1 parent 95e43e5 commit dbc708d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 76 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/npm-publish-all-packages-canary.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish canary of Artillery CLI to npm
name: Publish packages to NPM (canary)
on:
push:
branches:
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
COMMIT_SHA: ${{ github.sha }}
- run: |
export COMMIT_SHA=$(git rev-parse --short HEAD)
node .github/workflows/scripts/replace-package-versions-with-commit-sha.js
node .github/workflows/scripts/replace-package-versions.js
# It must be published in this specific order to account for order of dependencies (e.g. artillery depends on commons, core, etc), in case failures happen in publishing.
- run: npm -w @artilleryio/int-commons publish --tag canary
- run: npm -w @artilleryio/int-core publish --tag canary
Expand Down
19 changes: 12 additions & 7 deletions .github/workflows/npm-publish-all-packages.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Publish packages to CLI
name: Publish packages to NPM
on:
workflow_dispatch:
push:
branches:
- main
Expand All @@ -9,7 +10,9 @@ on:

jobs:
publish-fargate-worker-image:
if: "contains( github.event.head_commit.message, 'ci: release v')"
if: >
github.event_name == 'workflow_dispatch' ||
contains(github.event.head_commit.message, 'ci: release v')
uses: ./.github/workflows/docker-ecs-worker-image.yml
permissions:
contents: read
Expand All @@ -19,7 +22,9 @@ jobs:

publish-packages-to-npm:
runs-on: ubuntu-latest
if: "contains( github.event.head_commit.message, 'ci: release v')"
if: >
github.event_name == 'workflow_dispatch' ||
contains(github.event.head_commit.message, 'ci: release v')
needs: publish-fargate-worker-image
permissions:
contents: read
Expand Down Expand Up @@ -48,9 +53,7 @@ jobs:
- run: node .github/workflows/scripts/replace-worker-version-in-js-file.js
env:
COMMIT_SHA: ${{ github.sha }}
- run: node .github/workflows/scripts/rename-packages-to-correct-version.js
env:
PACKAGES_TO_REPLACE: ${{ env.PACKAGES_TO_RELEASE }}
- run: node .github/workflows/scripts/replace-package-versions.js
# It must be published in this specific order to account for order of dependencies (e.g. artillery depends on commons, core, etc), in case failures happen in publishing.
- run: npm -w @artilleryio/int-commons publish
- run: npm -w @artilleryio/int-core publish
Expand All @@ -59,7 +62,6 @@ jobs:
- run: npm -w artillery-plugin-metrics-by-endpoint publish
- run: npm -w artillery-plugin-ensure publish
- run: npm -w artillery-plugin-apdex publish
- run: npm -w artillery-engine-posthog publish
- run: npm -w artillery-engine-playwright publish
- run: npm -w artillery-plugin-fake-data publish
- run: npm -w artillery publish
Expand All @@ -70,6 +72,9 @@ jobs:

publish-official-docker-image:
uses: ./.github/workflows/docker-publish-artillery.yml
if: >
github.event_name == 'workflow_dispatch' ||
contains(github.event.head_commit.message, 'ci: release v')
needs: publish-packages-to-npm
with:
COMMIT_SHA: ${{ github.sha }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish-artillery-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
scope: '@artilleryio'
- run: PACKAGE_FOLDER_NAME=types node .github/workflows/scripts/rename-packages-to-correct-version.js
- run: .github/workflows/scripts/replace-package-versions.js
- run: npm ci
- run: npm -w '@artilleryio/types' publish --access public
env:
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/npm-publish-specific-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ jobs:
- run: node .github/workflows/scripts/replace-worker-version-in-js-file.js
env:
COMMIT_SHA: ${{ github.sha }}
- run: node .github/workflows/scripts/rename-packages-to-correct-version.js
- run: node .github/workflows/scripts/replace-package-versions.js
if: ${{ inputs.CHANNEL == 'latest'}}
env:
PACKAGES_TO_REPLACE: ${{ inputs.PACKAGE_FOLDER_NAME }}
- run: |
export COMMIT_SHA=$(git rev-parse --short HEAD)
node .github/workflows/scripts/replace-package-versions-with-commit-sha.js
node .github/workflows/scripts/replace-package-versions.js
if: ${{ inputs.CHANNEL == 'canary'}}
- name: Get corresponding package name from package.json
Expand Down
61 changes: 0 additions & 61 deletions .github/workflows/scripts/rename-packages-to-correct-version.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ const path = require('path');
const packagesDir = '../../../packages';
const commitSha = process.env.COMMIT_SHA;

const getNewVersion = (version) => `${version}-${commitSha}`;
const getNewVersion = (version) => {
if (!commitSha) {
return version;
}

return `${version}-${commitSha}`;
};

let versionMapping = {};

Expand Down Expand Up @@ -56,6 +62,10 @@ const updateDependencies = (pkg) => {
//replace the dependency we care about in this package with its corrected canary version
dependencies[packageNameToReplace] =
versionMapping[packageNameToReplace].content.version;

console.log(
`Updated dependency ${packageNameToReplace} in ${pkg.content.name} to ${dependencies[packageNameToReplace]}`
);
}
}
};
Expand Down

0 comments on commit dbc708d

Please sign in to comment.