Skip to content

Commit

Permalink
Merge 40c72bf into 6ed3a9e
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Feb 24, 2020
2 parents 6ed3a9e + 40c72bf commit 318aafd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ The following env vars are read for CircleCI users.
- `CIRCLE_PROJECT_REPONAME` - The name of the repository of the current project.
- `CIRCLE_PROJECT_USERNAME` - The GitHub or Bitbucket username of the current project.
- `CI_URL="https://circleci.com/api/v1.1/project"`
- `CIRCLE_PROJECT_ID` - This project ID used in artefact URLS

If you wish to use another CI provider, you can pass any name other than `circleci` into the CLI flag `--ci-provider`, which will allow you to enter your own environment variables for CI.

Expand All @@ -179,6 +180,41 @@ If you wish to use another CI provider, you can pass any name other than `circle
- `CI_PROJECT_REPONAME`
- `CI_PROJECT_USERNAME`

### CircleCI Artifact Notes

CircleCI have recently changed the API for retrieving API's. A URL is generated for artefacts in the format

`https://${CI_BUILD_NUM}-${CI_PROJECT_ID}-gh.circle-artifacts.com/0`

You can get the `CIRCLE_PROJECT_ID` by checking [https://circleci.com/docs/api/#artifacts-of-a-build](https://circleci.com/docs/api/#artifacts-of-a-build)

For example. the ID for this project is `177880476`, you can see it in the following URL

`https://circleci.com/api/v1.1/project/github/YOU54F/cypress-slack-reporter/1/artifacts`

which will return

```json
[ {
"path" : "root/app/mochareports/.gitignore",
"pretty_path" : "root/app/mochareports/.gitignore",
"node_index" : 0,
"url" : "https://1-177880476-gh.circle-artifacts.com/0/root/app/mochareports/.gitignore"
},
...
]
```

In order to correctly construct your artifact URL, you will need to manually retrieve this ID and set it as an env var titled `CIRCLE_PROJECT_ID`

`EXPORT CIRCLE_PROJECT_ID=177880476`

in windows

`SET CIRCLE_PROJECT_ID=177880476`

or in your CircleCI project's environment page.

## Scripted Runner

An example script is [here](./cli/spec.ts) as `cli/spec/ts`
Expand Down
1 change: 1 addition & 0 deletions config.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ CIRCLE_USERNAME=YOU54F
LOG_LEVEL=debug
CIRCLE_JOB=jobName
ENV_SUT=envsut
CIRCLE_PROJECT_ID=177880476
8 changes: 3 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ try {
}
}

const base = process.env.PWD || ".";

program
.version(
`git@github.com:YOU54F/cypress-slack-reporter.git@${version}`,
Expand Down Expand Up @@ -62,9 +60,9 @@ program

const ciProvider: string = program.ciProvider;
const vcsProvider: string = program.vcsProvider;
const reportDirectory: string = base + "/" + program.reportDir;
const videoDirectory: string = base + "/" + program.videoDir;
const screenshotDirectory: string = base + "/" + program.screenshotDir;
const reportDirectory: string = program.reportDir;
const videoDirectory: string = program.videoDir;
const screenshotDirectory: string = program.screenshotDir;
const verbose: boolean = program.verbose;

if (program.verbose || program.logger) {
Expand Down
5 changes: 4 additions & 1 deletion src/slack/slack-alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let {
CI_URL,
CI_CIRCLE_JOB
} = process.env;
const { CIRCLE_PROJECT_ID } = process.env;
const ENV_SUT = process.env.ENV_SUT;
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL as string;
let commitUrl: string = "";
Expand Down Expand Up @@ -406,8 +407,10 @@ export function buildHTMLReportURL(_reportDir: string, _artefactUrl: string) {
export function getArtefactUrl(_vcsRoot: string, _artefactUrl: string) {
switch (_vcsRoot) {
case "github":
_artefactUrl = `https://${CI_BUILD_NUM}-${CIRCLE_PROJECT_ID}-gh.circle-artifacts.com/0`;
break;
case "bitbucket":
_artefactUrl = `${CI_URL}/${_vcsRoot}/${CI_PROJECT_USERNAME}/${CI_PROJECT_REPONAME}/${CI_BUILD_NUM}/artifacts/0`;
_artefactUrl = `https://${CI_BUILD_NUM}-${CIRCLE_PROJECT_ID}-bb.circle-artifacts.com/0`;
break;
default: {
_artefactUrl = "";
Expand Down

0 comments on commit 318aafd

Please sign in to comment.