Skip to content

Commit 78b7ac8

Browse files
committed
fine tune
1 parent e0d2adf commit 78b7ac8

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

services/actions/init.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ func initGlobalRunnerToken(ctx context.Context) error {
4545
if err != nil && !errors.Is(err, util.ErrNotExist) {
4646
return fmt.Errorf("unable to check existing token: %w", err)
4747
}
48-
if existing != nil && !existing.IsActive {
49-
log.Warn("The token defined by GITEA_RUNNER_REGISTRATION_TOKEN is already invalidated, please use the latest one from web UI")
48+
if existing != nil {
49+
if !existing.IsActive {
50+
log.Warn("The token defined by GITEA_RUNNER_REGISTRATION_TOKEN is already invalidated, please use the latest one from web UI")
51+
}
5052
return nil
5153
}
5254
_, err = actions_model.NewRunnerTokenWithValue(ctx, 0, 0, token)

services/actions/init_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ func TestInitToken(t *testing.T) {
4545
require.NoError(t, err)
4646
token := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunnerToken{Token: tokenValue})
4747
assert.True(t, token.IsActive)
48+
49+
// init with the same token again, should not create a new token
50+
err = initGlobalRunnerToken(db.DefaultContext)
51+
require.NoError(t, err)
52+
token2 := unittest.AssertExistsAndLoadBean(t, &actions_model.ActionRunnerToken{Token: tokenValue})
53+
assert.Equal(t, token.ID, token2.ID)
54+
assert.True(t, token.IsActive)
4855
})
4956

5057
t.Run("EnvFileToken", func(t *testing.T) {

0 commit comments

Comments
 (0)