Skip to content

Commit

Permalink
quick fix
Browse files Browse the repository at this point in the history
  • Loading branch information
NorseGaud committed Mar 25, 2024
1 parent f7c2355 commit abea807
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:

jobs:
test:
runs-on: [ "self-hosted", "anka", "anka-template:d792c6f6-198c-470f-9526-9c998efe7ab4", "run-id:${{ github.run_id }}" ]
runs-on: [ "self-hosted", "anka", "anka-template:d792c6f6-198c-470f-9526-9c998efe7ab4", "run-id:${{ github.run_id }}", "job-id:1" ]
steps:
- uses: actions/checkout@v3
- run: |
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# ANKLET


- job-id is a label that is used to ensure that jobs in the same run don't compete for the same runner
- run-id is a label that is used to ensure that jobs in the same workspace don't compete for the same runner

24 changes: 9 additions & 15 deletions plugins/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func Run(ctx context.Context, logger *slog.Logger) {
for _, workflowRun := range (*workflow_runs).WorkflowRuns {
if *workflowRun.Status == "queued" {
ctx = logging.AppendCtx(ctx, slog.String("workflow_run", *workflowRun.Name))
ctx = logging.AppendCtx(ctx, slog.Int64("workflow_run_id", *workflowRun.ID))
logger.InfoContext(ctx, "found workflow run")
workflowRunJSON, err := json.MarshalIndent(workflowRun, "", " ")
if err != nil {
Expand Down Expand Up @@ -161,17 +162,20 @@ func Run(ctx context.Context, logger *slog.Logger) {
logger.DebugContext(ctx, "workflow run job json", "data", string(workflowJobJSON))
}

// get the run id, so we can ensure the runner doesn't run on a different job/run
// get the run id
// this ensures that jobs in the same workspace don't compete for the same runner
runID := extractLabelValue(job.Labels, "run-id:")
if runID == "" {
logging.Panic(ctx, "run-id label not found or empty; something wrong with your yaml")
}
ctx = logging.AppendCtx(ctx, slog.String("workflow_run_id", runID))

// runIDInt, err := strconv.ParseInt(runID, 10, 64)
// if err != nil {
// logging.Panic(ctx, "error converting runID to int64: "+err.Error())
// }
// get the unique job-id for this job
// this ensures that multiple jobs in the same run don't compete for the same runner
jobID := extractLabelValue(job.Labels, "job-id:")
if jobID == "" {
logging.Panic(ctx, "job-id label not found or empty; something wrong with your yaml")
}

// get other labels to know what VM to start
ankaTemplate := extractLabelValue(job.Labels, "anka-template:")
Expand Down Expand Up @@ -290,16 +294,6 @@ func Run(ctx context.Context, logger *slog.Logger) {
logCounter := 0
for !jobCompleted {
time.Sleep(5 * time.Second) // Wait before checking the job status again
// currentRun, _, err := githubClient.Actions.GetWorkflowRunByID(context.Background(), service.Owner, service.Repo, runIDInt)
// if err != nil {
// logging.Panic(ctx, err.Error())
// }
// if *currentRun.Status == "completed" {
// jobCompleted = true
// logger.InfoContext(ctx, "run completed", "run_id", runID)
// } else if logCounter%2 == 0 {
// logger.InfoContext(ctx, "run still in progress", "run_id", runID)
// }
currentJob, _, err := githubClient.Actions.GetWorkflowJobByID(context.Background(), service.Owner, service.Repo, *job.ID)
fmt.Println("currentJob:", currentJob)
if err != nil {
Expand Down

0 comments on commit abea807

Please sign in to comment.