bitrise-api-cli 0.0.1 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -6
- package/dist/bin.js +38 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,21 +1,120 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Bitrise API CLI [](https://www.npmjs.com/package/bitrise-api-cli)
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
<div align="center">
|
|
4
|
+
🚀 An unofficial CLI tool to interact with Bitrise API, making artifact downloads a breeze.
|
|
5
|
+
</div>
|
|
5
6
|
|
|
6
|
-
##
|
|
7
|
+
## 🎯 Features
|
|
8
|
+
|
|
9
|
+
- Download artifacts from your latest successful builds
|
|
10
|
+
- Simple workflow-based artifact retrieval
|
|
11
|
+
- Easy integration with CI/CD pipelines
|
|
12
|
+
- Supports both CLI arguments and environment variables
|
|
13
|
+
|
|
14
|
+
## 🚀 Quick Start
|
|
15
|
+
|
|
16
|
+
### Download Artifacts
|
|
7
17
|
|
|
8
18
|
```bash
|
|
19
|
+
# Using npx (recommended)
|
|
9
20
|
npx bitrise-api-cli@latest download --token <BITRISE_TOKEN> --workflow <WORKFLOW_NAME>
|
|
10
21
|
|
|
11
|
-
|
|
22
|
+
# If running locally, you'll need to specify the app slug
|
|
23
|
+
npx bitrise-api-cli@latest download \
|
|
24
|
+
--token <BITRISE_TOKEN> \
|
|
25
|
+
--workflow <WORKFLOW_NAME> \
|
|
26
|
+
--slug <APP_SLUG>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 🔐 Configuration
|
|
12
30
|
|
|
13
|
-
|
|
31
|
+
### Environment Variables
|
|
14
32
|
|
|
33
|
+
| Variable | Description | Required |
|
|
34
|
+
| -------------------------- | ---------------------------------------- |--------------|
|
|
35
|
+
| `BITRISE_API_CLI_TOKEN` | Your Bitrise API token | Yes |
|
|
36
|
+
| `BITRISE_API_CLI_WORKFLOW` | Workflow name to download artifacts from | Yes |
|
|
37
|
+
| `BITRISE_APP_SLUG` | App Slug (auto-set in Bitrise CI) | only locally |
|
|
38
|
+
|
|
39
|
+
### CLI Options
|
|
40
|
+
|
|
41
|
+
```bash
|
|
15
42
|
Options:
|
|
16
43
|
-t, --token <TOKEN> bitrise api token (or $BITRISE_API_CLI_TOKEN)
|
|
17
44
|
-w, --workflow <WORKFLOW_NAME> workflow to get apk from (or $BITRISE_API_CLI_WORKFLOW)
|
|
45
|
+
-s, --slug <APP_SLUG> bitrise app slug (or $BITRISE_APP_SLUG) see bitrise project url to get slug
|
|
46
|
+
-a, --artifact <ARTIFACT_TYPE> bitrise artifact type "ios-ipa" or "android-apk"
|
|
18
47
|
-d, --debug output extra debugging (default: false)
|
|
19
48
|
-h, --help display help for command
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 💡 Examples
|
|
52
|
+
|
|
53
|
+
### Using Command Line Arguments
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Download artifacts from a specific workflow
|
|
57
|
+
npx bitrise-api-cli@latest download \
|
|
58
|
+
--token abc123 \
|
|
59
|
+
--workflow android-release \
|
|
60
|
+
--slug a1b2c3d4e5f6
|
|
61
|
+
|
|
62
|
+
# Enable debug logging
|
|
63
|
+
npx bitrise-api-cli@latest download --debug \
|
|
64
|
+
--token abc123 \
|
|
65
|
+
--workflow android-release
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Using Environment Variables
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# Set environment variables
|
|
72
|
+
export BITRISE_API_CLI_TOKEN=abc123
|
|
73
|
+
export BITRISE_API_CLI_WORKFLOW=android-release
|
|
74
|
+
export BITRISE_APP_SLUG=a1b2c3d4e5f6
|
|
20
75
|
|
|
76
|
+
# Run the command
|
|
77
|
+
npx bitrise-api-cli@latest download
|
|
21
78
|
```
|
|
79
|
+
|
|
80
|
+
## 🔍 Common Use Cases
|
|
81
|
+
|
|
82
|
+
### CI/CD Integration
|
|
83
|
+
|
|
84
|
+
Perfect for downloading artifacts from previous builds instead of rebuilding from source:
|
|
85
|
+
|
|
86
|
+
```yaml
|
|
87
|
+
steps:
|
|
88
|
+
- script:
|
|
89
|
+
inputs:
|
|
90
|
+
content: |
|
|
91
|
+
npx bitrise-api-cli download \
|
|
92
|
+
--workflow android-release \
|
|
93
|
+
--token $BITRISE_API_TOKEN
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Local Development
|
|
97
|
+
|
|
98
|
+
Download the latest artifacts to test without building:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npx bitrise-api-cli@latest download \
|
|
102
|
+
--token $BITRISE_API_TOKEN \
|
|
103
|
+
--workflow android-release \
|
|
104
|
+
--slug $BITRISE_APP_SLUG
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 📝 License
|
|
108
|
+
|
|
109
|
+
This project is [MIT](LICENSE) licensed.
|
|
110
|
+
|
|
111
|
+
## 🙏 Acknowledgments
|
|
112
|
+
|
|
113
|
+
- Thanks to [Bitrise](https://www.bitrise.io/) for their excellent API
|
|
114
|
+
- Built with ❤️ for the mobile CI/CD community
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
<div align="center">
|
|
119
|
+
<p>Found this project useful? Give it a ⭐️!</p>
|
|
120
|
+
</div>
|
package/dist/bin.js
CHANGED
|
@@ -3,19 +3,25 @@
|
|
|
3
3
|
// src/bin.ts
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
|
|
6
|
+
// src/cliOptions.types.ts
|
|
7
|
+
var validArtifactTypes = ["android-apk", "ios-ipa"];
|
|
8
|
+
|
|
6
9
|
// src/bitrise/env.ts
|
|
7
10
|
var ENV = {
|
|
8
|
-
appSlug:
|
|
11
|
+
appSlug: "",
|
|
9
12
|
token: "",
|
|
10
|
-
workflow: ""
|
|
13
|
+
workflow: "",
|
|
14
|
+
artifactType: "android-apk"
|
|
11
15
|
};
|
|
12
16
|
var saveOptions = (options) => {
|
|
13
|
-
ENV.
|
|
14
|
-
ENV.
|
|
17
|
+
ENV.appSlug = options.slug;
|
|
18
|
+
ENV.token = options.token;
|
|
19
|
+
ENV.workflow = options.workflow;
|
|
20
|
+
ENV.artifactType = options.artifact;
|
|
15
21
|
};
|
|
16
22
|
var isEnvValid = () => {
|
|
17
23
|
if (ENV.appSlug.length < 1) {
|
|
18
|
-
console.log("No
|
|
24
|
+
console.log("No app slug provided! (see --help for more information)");
|
|
19
25
|
return false;
|
|
20
26
|
}
|
|
21
27
|
if (ENV.token?.length < 1) {
|
|
@@ -26,6 +32,10 @@ var isEnvValid = () => {
|
|
|
26
32
|
console.log("No workflow provided! (see --help for more information)");
|
|
27
33
|
return false;
|
|
28
34
|
}
|
|
35
|
+
if (!validArtifactTypes.includes(ENV.artifactType)) {
|
|
36
|
+
console.log(`Invalid artifact type "${ENV.artifactType}"! (see --help for more information)`);
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
29
39
|
return true;
|
|
30
40
|
};
|
|
31
41
|
|
|
@@ -1453,13 +1463,20 @@ var fetchArtifactList = async (buildSlug) => {
|
|
|
1453
1463
|
if (!data) throw new Error("buildArtifact().artifactList returned no data");
|
|
1454
1464
|
return data;
|
|
1455
1465
|
};
|
|
1466
|
+
var fetchArtifactByType = async (buildSlug) => {
|
|
1467
|
+
const artifactInfo = await fetchArtifactList(buildSlug);
|
|
1468
|
+
const artifactMetadata = artifactInfo.find((artifact) => artifact.artifactType === ENV.artifactType);
|
|
1469
|
+
if (!artifactMetadata || !artifactMetadata.slug)
|
|
1470
|
+
throw new Error(`Found no ${ENV.artifactType} in build Slug: ${buildSlug}`);
|
|
1471
|
+
return artifactMetadata;
|
|
1472
|
+
};
|
|
1456
1473
|
|
|
1457
1474
|
// src/helper/debugLog.ts
|
|
1458
1475
|
var debugLog = (label, data) => console.log(`${label}: ${JSON.stringify(data, void 0, 2)}`);
|
|
1459
1476
|
|
|
1460
1477
|
// src/bitrise/fetchBuilds.ts
|
|
1461
1478
|
var getAllBuilds = async () => {
|
|
1462
|
-
const { data } = await api.builds().buildList({ appSlug: ENV.appSlug });
|
|
1479
|
+
const { data } = await api.builds().buildList({ appSlug: ENV.appSlug, status: 1 });
|
|
1463
1480
|
if (!data) throw Error("no build data");
|
|
1464
1481
|
return data;
|
|
1465
1482
|
};
|
|
@@ -1491,7 +1508,6 @@ var downloadFile = async (fileUrl, outputLocationPath) => {
|
|
|
1491
1508
|
};
|
|
1492
1509
|
|
|
1493
1510
|
// src/downloadLatestArtifacts.ts
|
|
1494
|
-
var targetArtifactType = "android-apk";
|
|
1495
1511
|
var downloadLatestArtifacts = async (options) => {
|
|
1496
1512
|
saveOptions(options);
|
|
1497
1513
|
if (!isEnvValid()) return process.exit(1);
|
|
@@ -1503,11 +1519,12 @@ var downloadLatestArtifacts = async (options) => {
|
|
|
1503
1519
|
console.log("Latest build contained no Slug");
|
|
1504
1520
|
return process.exit(1);
|
|
1505
1521
|
}
|
|
1506
|
-
const
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1522
|
+
const artifactMetadata = await oraPromise(fetchArtifactByType(latestBuild.slug), {
|
|
1523
|
+
text: "fetching artifact list",
|
|
1524
|
+
failText: (error) => `fetching artifact list failed with error: ${error}`
|
|
1525
|
+
});
|
|
1510
1526
|
if (options.debug) debugLog("artifactMetadata", artifactMetadata);
|
|
1527
|
+
if (!artifactMetadata || !artifactMetadata.slug) return process.exit(1);
|
|
1511
1528
|
const artifact = await oraPromise(
|
|
1512
1529
|
fetchArtifact({
|
|
1513
1530
|
artifactSlug: artifactMetadata.slug,
|
|
@@ -1528,5 +1545,14 @@ var downloadLatestArtifacts = async (options) => {
|
|
|
1528
1545
|
|
|
1529
1546
|
// src/bin.ts
|
|
1530
1547
|
var program = new Command();
|
|
1531
|
-
program.
|
|
1548
|
+
program.version("0.0.4");
|
|
1549
|
+
program.command("download").option("-t, --token <TOKEN>", "bitrise api token (or $BITRISE_API_CLI_TOKEN)", process.env.BITRISE_API_CLI_TOKEN).option(
|
|
1550
|
+
"-w, --workflow <WORKFLOW_NAME>",
|
|
1551
|
+
"workflow to get apk from (or $BITRISE_API_CLI_WORKFLOW)",
|
|
1552
|
+
process.env.BITRISE_API_CLI_WORKFLOW
|
|
1553
|
+
).option(
|
|
1554
|
+
"-s, --slug <APP_SLUG>",
|
|
1555
|
+
"bitrise app slug (or $BITRISE_APP_SLUG) see bitrise project url to get slug",
|
|
1556
|
+
process.env.BITRISE_APP_SLUG
|
|
1557
|
+
).option("-a, --artifact <ARTIFACT_TYPE>", 'bitrise artifact type "ios-ipa" or "android-apk"', "android-apk").option("-d, --debug", "output extra debugging", false).description("Download bitrise artifacts").action((options) => downloadLatestArtifacts(options).catch(() => process.exit(1)));
|
|
1532
1558
|
program.parse(process.argv);
|