-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scripts: move snap release from GitHubCI to GitLabCI
The reason to use SNAPCRAFT_LOGIN_FILE instead of SNAPCRAFT_LOGIN (like in Github) is in the docs: From https://docs.gitlab.com/ee/ci/variables/#cicd-variable-types : ... File type variables: Consist of a key, value and file. Are made available in jobs as environment variables, with The CI/CD variable key as the environment variable name. The CI/CD variable value saved to a temporary file. The path to the temporary file as the environment variable value. ... And the reason for using "needs:" instead of "dependencies:" is because the job depends on artifacts of a job in the same stage. More info: https://gitlab.com/gitlab-org/gitlab/-/issues/30632 Co-authored-by: Andres G. Aragoneses <[email protected]>
- Loading branch information
Showing
4 changed files
with
170 additions
and
31 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
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,79 @@ | ||
namespace GWallet.Github | ||
|
||
open System | ||
open System.IO | ||
open System.Linq | ||
open System.Threading | ||
open System.Text | ||
open System.Configuration | ||
open System.Net.Http | ||
open System.Net.Http.Headers | ||
open System.Web.Script.Serialization | ||
open System.Collections | ||
open System.Collections.Generic | ||
|
||
module GithubActions = | ||
let private SendRequest (url: string) = | ||
async { | ||
use client = new HttpClient() | ||
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue.Parse "application/vnd.github.v3+json") | ||
client.DefaultRequestHeaders.UserAgent.Add(ProductInfoHeaderValue("CIChecker", "1.0.0")) | ||
return! client.GetStringAsync url |> Async.AwaitTask | ||
} | ||
|
||
let private QueryRunCount (status: string) (lastCommit: string) currentBranch = | ||
async { | ||
let url = | ||
sprintf | ||
"https://api.github.com/repos/nblockchain/geewallet/actions/runs?status=%s&branch=%s" | ||
status | ||
currentBranch | ||
|
||
Console.WriteLine (sprintf "Querying github API: %s" url) | ||
|
||
let! response = SendRequest url | ||
|
||
let responseObj = | ||
JavaScriptSerializer().Deserialize<Dictionary<string, obj>> response | ||
|
||
match responseObj.TryGetValue "workflow_runs" with | ||
| true, workflowRuns -> | ||
match workflowRuns with | ||
| :? ArrayList as runsArray -> | ||
return | ||
runsArray.OfType<Dictionary<string, obj>>() | ||
|> Seq.filter | ||
(fun run -> | ||
match run.TryGetValue "head_sha" with | ||
| false, _ -> | ||
failwithf "Couldn't find 'head_sha' in sub-JSON: %s" response | ||
| true, headSha -> | ||
match headSha with | ||
| :? string as headShaString -> | ||
lastCommit.StartsWith headShaString || headShaString.StartsWith lastCommit | ||
| _ -> | ||
failwithf "Couldn't cast 'head_sha' to string: %s" response | ||
) | ||
|> Seq.length | ||
| _ -> return failwithf "Couldn't cast 'workflow_runs' to ArrayList: %s" response | ||
| false, _ -> | ||
return failwithf "Couldn't find 'workflow_runs' in JSON: %s" response | ||
|
||
} | ||
|
||
let private CheckAllRuns lastCommit currentBranch = | ||
async { | ||
let! successfulCount = QueryRunCount "success" lastCommit currentBranch | ||
let! failedCount = QueryRunCount "failure" lastCommit currentBranch | ||
|
||
if failedCount > 0 || successfulCount < 1 then | ||
return false | ||
else | ||
return true | ||
} | ||
|
||
let MakeSureGithubCIPassed (lastCommit: string) (currentBranch: string) = | ||
if CheckAllRuns lastCommit currentBranch |> Async.RunSynchronously then | ||
Console.WriteLine (sprintf "GitHubCI is green for branch %s (commit %s)" currentBranch lastCommit) | ||
else | ||
failwithf "Failed job in GitHub: https://github.com/nblockchain/geewallet/commit/%s" lastCommit |
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