Skip to content

Commit

Permalink
fix: use workflow runs
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Dec 9, 2024
1 parent 36e2291 commit bd0af4d
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ jobs:
E2E: "1"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_JOB_ID: ${{ github.job }}
GITHUB_RUN_ID: ${{ github.run_id }}
GITHUB_RUN_ATTEMPT: ${{ github.run_attempt }}
run: go test -timeout 15m -v -run TestIntegration ./...
16 changes: 10 additions & 6 deletions _oas/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ paths:
- repo_owner
- repo_name
- commit_sha
- job_id
- job_run_id
- job_run_number
- job
- run_id
- run_attempt
properties:
repo_owner:
type: string
Expand All @@ -95,10 +95,14 @@ paths:
type: string
description: "Repository name"
example: "repo"
job_id:
type: integer
job:
type: string
description: "Job ID"
example: 123456789
run_id:
type: integer
format: int64
run_attempt:
type: integer
responses:
200:
description: "Telegram account acquired"
Expand Down
13 changes: 8 additions & 5 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ func TestIntegration(t *testing.T) {
t.Skip("E2E=1 not set")
}

jobID, err := strconv.Atoi(os.Getenv("GITHUB_JOB_ID"))
require.NoError(t, err)
jobID := os.Getenv("GITHUB_JOB_ID")
runID, _ := strconv.ParseInt(os.Getenv("GITHUB_RUN_ID"), 10, 64)
attempt, _ := strconv.Atoi(os.Getenv("GITHUB_RUN_ATTEMPT"))

ctx := context.Background()
client, err := oas.NewClient("https://bot.gotd.dev", securitySource{})
Expand All @@ -94,9 +95,11 @@ func TestIntegration(t *testing.T) {

res, err := backoff.RetryNotifyWithData(func() (*oas.AcquireTelegramAccountOK, error) {
return client.AcquireTelegramAccount(ctx, &oas.AcquireTelegramAccountReq{
RepoOwner: "gotd",
RepoName: "bot",
JobID: jobID,
RepoOwner: "gotd",
RepoName: "bot",
RunID: runID,
Job: jobID,
RunAttempt: attempt,
})
}, bo, func(err error, duration time.Duration) {
t.Logf("Error: %v, retrying in %v", err, duration)
Expand Down
4 changes: 2 additions & 2 deletions internal/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ func (h Handler) AcquireTelegramAccount(ctx context.Context, req *oas.AcquireTel
if err != nil {
return nil, errors.Wrap(err, "get repo")
}
job, _, err := client.Actions.GetWorkflowJobByID(ctx, req.RepoOwner, req.RepoName, int64(req.JobID))
wr, _, err := client.Actions.GetWorkflowRunByID(ctx, req.RepoOwner, req.RepoName, req.RunID)
if err != nil {
return nil, errors.Wrap(err, "get job")
}
zctx.From(ctx).Info("AcquireTelegramAccount",
zap.String("repo", repo.GetFullName()),
zap.String("job", job.GetName()),
zap.String("run", wr.GetName()),
)

lease, err := h.manager.Acquire()
Expand Down
12 changes: 11 additions & 1 deletion internal/oas/oas_faker_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 42 additions & 8 deletions internal/oas/oas_json_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 29 additions & 7 deletions internal/oas/oas_schemas_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bd0af4d

Please sign in to comment.