-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Cider for version increment, and created a release script.
- Loading branch information
1 parent
2bde7cf
commit a280ee7
Showing
4 changed files
with
158 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
## 1.0.0 | ||
# 0.0.1-alpha | ||
|
||
- Initial version. | ||
This is the first alpha version of Arceus. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:yaml/yaml.dart'; | ||
|
||
Future<void> main(List<String> args) async { | ||
// Configuration | ||
const repoOwner = 'DrRetro2033'; // Replace with your GitHub username or org | ||
const repoName = 'Arceus'; // Replace with your repository name | ||
|
||
final apiBase = 'https://api.github.com/repos/$repoOwner/$repoName'; | ||
final token = String.fromEnvironment('GITHUB_TOKEN'); | ||
if (args.isEmpty) { | ||
print('Usage: dart release.dart <path-to-project>'); | ||
exit(1); | ||
} | ||
final pathOfProject = args.first; | ||
if (!Directory(pathOfProject).existsSync()) { | ||
print('Error: Directory not found: $pathOfProject'); | ||
exit(1); | ||
} | ||
final downloadedFiles = <File>[]; // List of downloaded artifacts | ||
try { | ||
// Step 1: Fetch the most recent workflow run | ||
print('Fetching latest workflow run...'); | ||
final workflowsResponse = await http.get( | ||
Uri.parse('$apiBase/actions/runs'), | ||
headers: {'Authorization': 'token $token'}, | ||
); | ||
|
||
if (workflowsResponse.statusCode != 200) { | ||
throw Exception( | ||
'Failed to fetch workflow runs: ${workflowsResponse.body}'); | ||
} | ||
|
||
final workflowsData = jsonDecode(workflowsResponse.body); | ||
final latestRun = workflowsData['workflow_runs']?.first; | ||
if (latestRun == null) { | ||
throw Exception('No workflow runs found.'); | ||
} | ||
|
||
final runId = latestRun['id']; | ||
print('Latest workflow run ID: $runId'); | ||
|
||
// Step 2: Fetch artifacts from the latest run | ||
print('Fetching artifacts...'); | ||
final artifactsResponse = await http.get( | ||
Uri.parse('$apiBase/actions/runs/$runId/artifacts'), | ||
headers: {'Authorization': 'token $token'}, | ||
); | ||
|
||
if (artifactsResponse.statusCode != 200) { | ||
throw Exception('Failed to fetch artifacts: ${artifactsResponse.body}'); | ||
} | ||
|
||
final artifactsData = jsonDecode(artifactsResponse.body)['artifacts']; | ||
if (artifactsData.isEmpty) { | ||
throw Exception('No artifacts found for the latest workflow run.'); | ||
} | ||
|
||
// Download artifacts | ||
for (final artifact in artifactsData) { | ||
final artifactId = artifact['id']; | ||
final artifactName = artifact['name']; | ||
print('Downloading artifact: $artifactName...'); | ||
|
||
final artifactDownloadResponse = await http.get( | ||
Uri.parse('$apiBase/actions/artifacts/$artifactId/zip'), | ||
headers: {'Authorization': 'token $token'}, | ||
); | ||
|
||
if (artifactDownloadResponse.statusCode != 200) { | ||
throw Exception( | ||
'Failed to download artifact: ${artifactDownloadResponse.body}'); | ||
} | ||
|
||
final outputFile = File('$artifactName.zip'); | ||
await outputFile.writeAsBytes(artifactDownloadResponse.bodyBytes); | ||
downloadedFiles.add(outputFile); | ||
print('Artifact downloaded: ${outputFile.path}'); | ||
} | ||
|
||
// Step 3: Create a release | ||
print('Creating release...'); | ||
final createReleaseResponse = await http.post( | ||
Uri.parse('$apiBase/releases'), | ||
headers: { | ||
'Authorization': 'token $token', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: jsonEncode({ | ||
'tag_name': | ||
'v${loadYaml(File("$pathOfProject/pubspec.yaml").readAsStringSync())['version']}', | ||
'name': | ||
'v${loadYaml(File("$pathOfProject/pubspec.yaml").readAsStringSync())['version']}', | ||
'body': File('$pathOfProject/CHANGELOG.md').readAsStringSync(), | ||
'draft': true, | ||
'prerelease': true, | ||
}), | ||
); | ||
|
||
if (createReleaseResponse.statusCode != 201) { | ||
throw Exception( | ||
'Failed to create release: ${createReleaseResponse.body}'); | ||
} | ||
|
||
final releaseData = jsonDecode(createReleaseResponse.body); | ||
final uploadUrl = | ||
releaseData['upload_url'].toString().replaceAll('{?name,label}', ''); | ||
|
||
print('Release created: ${releaseData['html_url']}'); | ||
|
||
// Step 4: Upload artifacts to the release | ||
for (final file in downloadedFiles) { | ||
print('Uploading artifact: ${file.path}...'); | ||
final uploadResponse = await http.post( | ||
Uri.parse( | ||
'$uploadUrl?name=${Uri.encodeComponent(file.uri.pathSegments.last)}'), | ||
headers: { | ||
'Authorization': 'token $token', | ||
'Content-Type': 'application/octet-stream', | ||
}, | ||
body: await file.readAsBytes(), | ||
); | ||
|
||
if (uploadResponse.statusCode != 201) { | ||
throw Exception('Failed to upload artifact: ${uploadResponse.body}'); | ||
} | ||
|
||
final uploadedAsset = jsonDecode(uploadResponse.body); | ||
print('Artifact uploaded: ${uploadedAsset['browser_download_url']}'); | ||
} | ||
|
||
print('Release process completed successfully!'); | ||
} catch (e) { | ||
print('Error: $e'); | ||
} | ||
for (File downloadedFile in downloadedFiles) { | ||
downloadedFile.deleteSync(); | ||
} | ||
} |