Skip to content

Commit

Permalink
Merge pull request #140 from adobe/sync_secrets_epic_branch
Browse files Browse the repository at this point in the history
Sync secrets epic branch
  • Loading branch information
revanth0212 authored Jun 10, 2024
2 parents 2ae2576 + e842bc6 commit efee233
Show file tree
Hide file tree
Showing 17 changed files with 686 additions and 137 deletions.
85 changes: 68 additions & 17 deletions .github/workflows/publish-to-npm.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,71 @@
name: publish-to-npm
on:
pull_request:
types: [closed]
branches:
- main
pull_request:
types: [ closed ]
branches:
- main
- develop
- epic/**
jobs:
publish:
if: github.repository == 'adobe/aio-cli-plugin-api-mesh'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 18
- run: yarn install --frozen-lockfile
- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.ADOBE_BOT_NPM_TOKEN }}
access: 'public'
publish:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18

- name: Yarn install
run: yarn install --frozen-lockfile

- name: Get version from package.json
id: get_version
run: |
version=$(jq -r '.version' package.json)
echo "version=$version" >> $GITHUB_OUTPUT
echo "Read version $version from package.json"
- name: Verify version corresponds to branch
id: verify_version
run: |
target_branch="${GITHUB_REF#refs/heads/}"
version_tag=""
if [ "$target_branch" == "main" ]; then
version_tag="latest"
elif [ "$target_branch" == "develop" ]; then
if [[ "${{ steps.get_version.outputs.version }}" =~ beta ]]; then
version_tag="beta"
else
echo "Will not publish. Version on branch \"$target_branch\" is not beta.";
exit 0;
fi
elif [[ $target_branch == epic/* ]]; then
if [[ "${{ steps.get_version.outputs.version }}" =~ alpha ]]; then
version_tag="alpha"
else
echo "Will not publish. Version on branch \"$target_branch\" is not alpha.";
exit 0;
fi
else
echo "Will not publish. Branch \"$target_branch\" is not designated for publish.";
exit 0;
fi
echo "version_tag=$version_tag" >> $GITHUB_OUTPUT;
echo "Will publish version ${{ steps.get_version.outputs.version }} as $version_tag"
- name: Publish to npm
if: ${{ steps.verify_version.outputs.version_tag != '' }}
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.ADOBE_BOT_NPM_TOKEN }}
access: 'public'
tag: ${{ steps.verify_version.outputs.version_tag }}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"version": "oclif-dev readme && git add README.md"
},
"dependencies": {
"@adobe-apimesh/mesh-builder": "1.4.2",
"@adobe-apimesh/mesh-builder": "1.4.4",
"@adobe/aio-cli-lib-console": "^4.0.0",
"@adobe/aio-lib-core-config": "^3.0.0",
"@adobe/aio-lib-core-logging": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/__fixtures__/openapi-schema.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"$schema": "http://json-schema.org/draft-04/schema"
"$schema": "http://json-schema.org/draft-04/schema",
"id": "2"
}
130 changes: 122 additions & 8 deletions src/commands/api-mesh/__tests__/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ governing permissions and limitations under the License.

const mockConsoleCLIInstance = {};

jest.mock('axios');
jest.mock('@adobe/aio-lib-ims');
jest.mock('@adobe/aio-lib-env');
jest.mock('@adobe/aio-cli-lib-console', () => ({
init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
cleanStdOut: jest.fn(),
}));
jest.mock('../../../helpers', () => ({
initSdk: jest.fn().mockResolvedValue({}),
initRequestId: jest.fn().mockResolvedValue({}),
promptConfirm: jest.fn().mockResolvedValue(true),
interpolateMesh: jest.fn().mockResolvedValue({}),
importFiles: jest.fn().mockResolvedValue(),
}));
jest.mock('../../../lib/devConsole');

const CreateCommand = require('../create');
const sampleCreateMeshConfig = require('../../__fixtures__/sample_mesh.json');
const meshConfigWithComposerFiles = require('../../__fixtures__/sample_mesh_with_composer_files.json');
Expand All @@ -27,14 +43,14 @@ const {
createMesh,
createAPIMeshCredentials,
subscribeCredentialToMeshService,
getTenantFeatures,
} = require('../../../lib/devConsole');

const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };

const os = require('os');

const selectedProject = { id: '5678', title: 'Project01' };

const selectedWorkspace = { id: '123456789', title: 'Workspace01' };

jest.mock('@adobe/aio-cli-lib-console', () => ({
Expand All @@ -56,11 +72,11 @@ jest.mock('../../../helpers', () => ({
jest.mock('../../../lib/devConsole');
jest.mock('chalk', () => ({
red: jest.fn(text => text), // Return the input text without any color formatting
bold: jest.fn(text => text),
}));

let logSpy = null;
let errorLogSpy = null;

let parseSpy = null;
let platformSpy = null;

Expand All @@ -71,9 +87,12 @@ describe('create command tests', () => {
beforeEach(() => {
initSdk.mockResolvedValue({
imsOrgId: selectedOrg.id,
imsOrgCode: selectedOrg.code,
projectId: selectedProject.id,
workspaceId: selectedWorkspace.id,
workspaceName: selectedWorkspace.title,
orgName: selectedOrg.name,
projectName: selectedProject.title,
});

global.requestId = 'dummy_request_id';
Expand All @@ -95,14 +114,23 @@ describe('create command tests', () => {
apiKey: 'dummy_api_key',
id: 'dummy_id',
});

subscribeCredentialToMeshService.mockResolvedValue(['dummy_service']);

let fetchedMeshConfig = sampleCreateMeshConfig;
fetchedMeshConfig.meshId = 'dummy_id';
fetchedMeshConfig.meshURL = '';
getMesh.mockResolvedValue({
meshId: 'dummy_id',
meshURL: '',
});

getMesh.mockResolvedValue(fetchedMeshConfig);
getTenantFeatures.mockResolvedValue({
imsOrgId: selectedProject.code,
showCloudflareURL: false,
});

global.requestId = 'dummy_request_id';

logSpy = jest.spyOn(CreateCommand.prototype, 'log');
errorLogSpy = jest.spyOn(CreateCommand.prototype, 'error');
parseSpy = jest.spyOn(CreateCommand.prototype, 'parse');
parseSpy.mockResolvedValue({
args: { file: 'src/commands/__fixtures__/sample_mesh.json' },
Expand Down Expand Up @@ -300,6 +328,8 @@ describe('create command tests', () => {
"5678",
"123456789",
"Workspace01",
"ORG01",
"Project01",
{
"meshConfig": {
"sources": [
Expand Down Expand Up @@ -390,6 +420,8 @@ describe('create command tests', () => {
"5678",
"123456789",
"Workspace01",
"ORG01",
"Project01",
{
"meshConfig": {
"sources": [
Expand Down Expand Up @@ -949,6 +981,8 @@ describe('create command tests', () => {
"5678",
"123456789",
"Workspace01",
"ORG01",
"Project01",
{
"meshConfig": {
"files": [
Expand Down Expand Up @@ -1153,7 +1187,8 @@ describe('create command tests', () => {
`);
});

test('should not override if prompt returns No, if there is files array', async () => {
// Temporarily skipping since it is not actually testing the file import override prompt. The function which performs the prompt is mocked.
test.skip('should not override if prompt returns No, if there is files array', async () => {
let meshConfig = {
sources: [
{
Expand Down Expand Up @@ -1211,6 +1246,8 @@ describe('create command tests', () => {
"5678",
"123456789",
"Workspace01",
"ORG01",
"Project01",
{
"files": [
{
Expand Down Expand Up @@ -1280,7 +1317,8 @@ describe('create command tests', () => {
`);
});

test('should override if prompt returns Yes, if there is files array', async () => {
// Temporarily skipping since it is not actually testing the file import override prompt. The function which performs the prompt is mocked.
test.skip('should override if prompt returns Yes, if there is files array', async () => {
let meshConfig = {
sources: [
{
Expand Down Expand Up @@ -1340,6 +1378,8 @@ describe('create command tests', () => {
"5678",
"123456789",
"Workspace01",
"ORG01",
"Project01",
{
"meshConfig": {
"files": [
Expand Down Expand Up @@ -1472,6 +1512,8 @@ describe('create command tests', () => {
"5678",
"123456789",
"Workspace01",
"ORG01",
"Project01",
{
"meshConfig": {
"files": [
Expand Down Expand Up @@ -1601,6 +1643,8 @@ describe('create command tests', () => {
"5678",
"123456789",
"Workspace01",
"ORG01",
"Project01",
{
"meshConfig": {
"files": [
Expand Down Expand Up @@ -1763,6 +1807,76 @@ describe('create command tests', () => {
`);
});

test('should show prod edge mesh url on workspace named "Production" if feature is enabled', async () => {
// mock the edge mesh url feature to be enabled
getTenantFeatures.mockResolvedValue({
imsOrgId: selectedOrg.code,
showCloudflareURL: true,
});

// mock the workspace name to "Production"
initSdk.mockResolvedValue({
workspaceName: 'Production',
});

await CreateCommand.run();

expect(logSpy).toHaveBeenCalledWith(
expect.stringContaining('Legacy Mesh Endpoint:'),
'https://graph.adobe.io/api/dummy_mesh_id/graphql?api_key=dummy_api_key',
);

expect(logSpy).toHaveBeenCalledWith(
expect.stringContaining('Edge Mesh Endpoint:'),
'https://edge-graph.adobe.io/api/dummy_mesh_id/graphql',
);
});

test('should show sandbox edge mesh url on workspace NOT named "Production" if feature is enabled', async () => {
// mock the edge mesh url feature to be enabled
getTenantFeatures.mockResolvedValueOnce({
imsOrgId: selectedOrg.code,
showCloudflareURL: true,
});

// mock the workspace name to a value not equal to "Production"
initSdk.mockResolvedValueOnce({
workspaceName: 'AnythingButProduction',
});

await CreateCommand.run();

expect(logSpy).toHaveBeenCalledWith(
expect.stringContaining('Legacy Mesh Endpoint:'),
'https://graph.adobe.io/api/dummy_mesh_id/graphql?api_key=dummy_api_key',
);

expect(logSpy).toHaveBeenCalledWith(
expect.stringContaining('Edge Mesh Endpoint:'),
'https://edge-sandbox-graph.adobe.io/api/dummy_mesh_id/graphql',
);
});

test('should not show edge mesh url if feature is disabled', async () => {
// mock the edge mesh url feature to be disabled
getTenantFeatures.mockResolvedValueOnce({
imsOrgId: selectedOrg.code,
showCloudflareURL: false,
});

await CreateCommand.run();

expect(logSpy).not.toHaveBeenCalledWith(
expect.stringContaining('Edge Mesh Endpoint:'),
expect.any(String),
);

expect(logSpy).toHaveBeenCalledWith(
expect.stringContaining('Mesh Endpoint:'),
'https://graph.adobe.io/api/dummy_mesh_id/graphql?api_key=dummy_api_key',
);
});

test('should return error if mesh has placeholders and the provided secrets file is invalid', async () => {
parseSpy.mockResolvedValueOnce({
args: { file: 'src/commands/__fixtures__/sample_secrets_mesh.json' },
Expand Down
Loading

0 comments on commit efee233

Please sign in to comment.