Skip to content

Commit

Permalink
Merge pull request #1087 from crowdbotics/qa
Browse files Browse the repository at this point in the history
Merge QA to Master
  • Loading branch information
driverdan authored Feb 1, 2024
2 parents 8e533b7 + 78bf935 commit 9ee1682
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
- name: release modules
run: |
heroku config:set MODULES_REPO_BRANCH=$GITHUB_REF_NAME -a ${{ secrets.HEROKU_APP }}
heroku run 'python manage.py update_crowdbotics_components --quiet --no-input --no-log-file --public' --size=standard-2x -a ${{ secrets.HEROKU_APP }}
heroku run 'python manage.py update_crowdbotics_components --quiet --no-input --no-log-file --public' --size=standard-2x -a ${{ secrets.HEROKU_APP }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: release-notes
name: create-github-release

on:
workflow_dispatch:
Expand All @@ -7,17 +7,20 @@ on:
- create-github-release

jobs:

build:
runs-on: ubuntu-latest
env:
env:
working-directory: ./modules

steps:
- name: Repo Clone
- name: Repo Clone
run: |
git clone https://${{ secrets.GIT_TOKEN }}@github.com/crowdbotics/modules.git
- name: Clone Reusable Actions Repo
run: |
git clone -b master https://${{ secrets.GIT_TOKEN }}@github.com/crowdbotics/github-actions.git
- name: Checkout branch
working-directory: ${{ env.working-directory }}
run: |
Expand All @@ -29,10 +32,11 @@ jobs:
echo "branch: ${GITHUB_REF_NAME}"
git checkout ${GITHUB_REF_NAME}
fi
- name: Run Release Workflow
uses: crowdbotics/github-actions/create-github-release@master
uses: ./github-actions/create-github-release
with:
working-directory: ${{ env.working-directory }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
JIRA_TOKEN: ${{ secrets.JIRA_TOKEN }}
release_branch: ${{ github.event.client_payload.release_branch }}
38 changes: 38 additions & 0 deletions .github/workflows/release-to-qa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: release-to-qa

on:
workflow_dispatch:
repository_dispatch:
types:
- release-to-qa

jobs:
tag-and-pr:
runs-on: ubuntu-latest
env:
working-directory: ./modules
base-branch: qa
pr-branch: develop
pr-label: automerge
steps:
- name: Repo Clone
run: |
git clone https://${{ secrets.GIT_TOKEN }}@github.com/${{ github.repository }}.git
- name: Clone Reusable Actions Repo
run: |
git clone -b master https://${{ secrets.GIT_TOKEN }}@github.com/crowdbotics/github-actions.git
- name: Checkout branch
working-directory: ${{ env.working-directory }}
run: |
git checkout ${{ env.pr-branch }}
- name: Run Release to QA Workflow
uses: ./github-actions/release-to-qa
with:
working-directory: ${{ env.working-directory }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
base-branch: ${{ env.base-branch }}
pr-branch: ${{ env.pr-branch }}
pr-label: ${{ env.pr-label }}
29 changes: 24 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { login } from "./scripts/login.js";
import { configFile } from "./scripts/utils/configFile.js";
import { sendFeedback } from "./scripts/feedback.js";
import { logout } from "./scripts/logout.js";
import { modulesGet, modulesList } from "./scripts/modules.js";
import { modulesArchive, modulesGet, modulesList } from "./scripts/modules.js";
import { publish } from "./scripts/publish.js";
import { sendAmplitudeEvent } from "./scripts/amplitude/scripts.js";

Expand Down Expand Up @@ -258,7 +258,9 @@ demo`;
const args = arg({
"--search": String,
"--visibility": String,
"--page": String
"--status": String,
"--page": String,
"--unarchive": Boolean
});

let id;
Expand All @@ -275,6 +277,7 @@ demo`;
case "list":
modulesList({
search: args["--search"],
status: args["--status"],
visibility: args["--visibility"],
page: args["--page"] ? Number(args["--page"]) : undefined
});
Expand All @@ -291,12 +294,27 @@ demo`;
modulesGet(id);
break;

case "archive":
id = args._[2];
if (!id) {
return invalid(
"Please provide the id of the module to archive, i.e. modules archive <123>"
);
}

modulesArchive(id, !!args["--unarchive"]);
break;

case "help":
section(
`Commands available:
list List the current modules available to install
--search <query> Search for a module by given text
--visibility <private | public> Search for a module with a specific visibility (default all)
list List the current modules available to install
--search <query> Search for a module by given text
--status <published | archived> Search for a module by either published or archived modules (default all)
--visibility <private | public> Search for a module with a specific visibility (default all)
get <id> Get the details for the specified module
archive <id> Archive the specified module to prevent future installation to a project
--unarchive Undo the archive of the module to set the status back to Published
`
);
break;
Expand Down Expand Up @@ -353,6 +371,7 @@ Commands available:
login Login to your Crowdbotics account. Requires 2FA authentication
logout Logout of your Crowdbotics account
publish Publish your modules to your organization's private catalog
modules Manage modules for your organization
Parse and validate your modules:
npx crowdbotics/modules parse --source <path>
Expand Down
5 changes: 5 additions & 0 deletions scripts/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export const info = async () => {

const body = await response.json();

const organization = body.organization;
delete body.organization;
section("Current User:");
console.table(body);

section("Organization:");
console.table(organization);
};
70 changes: 67 additions & 3 deletions scripts/modules.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { invalid, section } from "../utils.js";
import { invalid, section, valid } from "../utils.js";
import { apiClient } from "./utils/apiClient.js";
import { configFile } from "./utils/configFile.js";
import { DEFAULT_HOST, HOST_CONFIG_NAME } from "./utils/constants.js";
import { getCurrentUserOrganization } from "./utils/organization.js";
import Table from "cli-table";
import ora from "ora";
import { formatUrlPath } from "./utils/url.js";
import inquirer from "inquirer";

const MODULES_PAGE_LIMIT = 50;

export const modulesList = async ({ search, visibility = "", page = 1 }) => {
export const modulesList = async ({
search,
status,
visibility = "",
page = 1
}) => {
const loadingSpinner = ora("Loading Modules").start();

try {
Expand All @@ -30,6 +36,10 @@ export const modulesList = async ({ search, visibility = "", page = 1 }) => {
params.visibility = "Private";
}

if (status) {
params.is_archived = status === "archived";
}

if (visibility.toLowerCase() === "public") {
params.visibility = "Public";
}
Expand Down Expand Up @@ -114,10 +124,64 @@ export const modulesGet = async (id) => {
section(`Description: \n${module.description}`);
section(`ID: \n${module.id}`);
section(`Slug: \n${module.slug}`);
section(`Visibility: \n${module.visibility}`);
section(`Public/Private: \n${module.visibility}`);
section(
`Published/Archived: \n${!module.is_archived ? "Published" : "Archived"}`
);

const host = configFile.get(HOST_CONFIG_NAME) || DEFAULT_HOST;
section(
`Module Details: ${formatUrlPath(host)}/dashboard/catalogs/${module.id}`
);
};

export const modulesArchive = async (id, unarchive = false) => {
const loadingSpinner = ora("Preparing request").start();

const moduleResponse = await apiClient.get({
path: `/v1/catalog/module/${id}`
});

loadingSpinner.stop();

if (!moduleResponse.ok) {
if (moduleResponse.status === 404) {
invalid(`Cannot find requested module with id ${id}.`);
} else {
invalid("Unable to get module. Please login and try again.");
}

return;
}

const verb = unarchive ? "unarchive" : "archive";

const module = await moduleResponse.json();

// Verify that the user understands which organization the modules are being published to.
const { ok } = await inquirer.prompt({
message: `Are you sure you want to ${verb} module: ${module.title}?`,
name: "ok",
type: "input",
default: "y/n"
});

if (ok.trim().toLowerCase() !== "y") {
invalid(`Cancelling operation. No module has been ${verb}d.`);
return;
}

const archivingSpinner = ora("Pending request").start();

const archiveResponse = await apiClient.post({
path: `/v1/catalog/module/${id}/${verb}`
});

archivingSpinner.stop();

if (archiveResponse.ok) {
valid(`Module: ${module.title} ${verb}d.`);
} else {
invalid(`Unable to ${verb} module: ${module.title}.`);
}
};

0 comments on commit 9ee1682

Please sign in to comment.