-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See [Defining outputs for jobs](https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs) and [Example usage of the needs context](https://docs.github.com/en/actions/learn-github-actions/contexts#example-usage-of-the-needs-context). Related to: - [actions-proto-def #5](https://gitea.com/gitea/actions-proto-def/pulls/5) - [act_runner #133](https://gitea.com/gitea/act_runner/pulls/133) <details> <summary>Tests & screenshots</summary> Test workflow file: ```yaml name: outputs on: push jobs: job1: runs-on: ubuntu-latest outputs: output1: ${{ steps.step1.outputs.output1 }} output2: ${{ steps.step2.outputs.output2 }} steps: - name: step1 id: step1 run: | date -Is > output1 cat output1 echo "output1=$(cat output1)" >> $GITHUB_OUTPUT - name: step2 id: step2 run: | cat /proc/sys/kernel/random/uuid > output2 cat output2 echo "output2=$(cat output2)" >> $GITHUB_OUTPUT job2: needs: job1 runs-on: ubuntu-latest steps: - run: echo ${{ needs.job1.outputs.output1 }} - run: echo ${{ needs.job1.outputs.output2 }} - run: echo ${{ needs.job1.result }} ``` <img width="397" alt="image" src="https://user-images.githubusercontent.com/9418365/233313322-903e7ebf-49a7-48e2-8c17-95a4581b3284.png"> <img width="385" alt="image" src="https://user-images.githubusercontent.com/9418365/233313442-30909135-1711-4b78-a5c6-133fcc79f47c.png"> </details> --------- Co-authored-by: Giteabot <teabot@gitea.io>
- Loading branch information
Showing
7 changed files
with
155 additions
and
4 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,51 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package actions | ||
|
||
import ( | ||
"context" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
) | ||
|
||
// ActionTaskOutput represents an output of ActionTask. | ||
// So the outputs are bound to a task, that means when a completed job has been rerun, | ||
// the outputs of the job will be reset because the task is new. | ||
// It's by design, to avoid the outputs of the old task to be mixed with the new task. | ||
type ActionTaskOutput struct { | ||
ID int64 | ||
TaskID int64 `xorm:"INDEX UNIQUE(task_id_output_key)"` | ||
OutputKey string `xorm:"VARCHAR(255) UNIQUE(task_id_output_key)"` | ||
OutputValue string `xorm:"MEDIUMTEXT"` | ||
} | ||
|
||
// FindTaskOutputByTaskID returns the outputs of the task. | ||
func FindTaskOutputByTaskID(ctx context.Context, taskID int64) ([]*ActionTaskOutput, error) { | ||
var outputs []*ActionTaskOutput | ||
return outputs, db.GetEngine(ctx).Where("task_id=?", taskID).Find(&outputs) | ||
} | ||
|
||
// FindTaskOutputKeyByTaskID returns the keys of the outputs of the task. | ||
func FindTaskOutputKeyByTaskID(ctx context.Context, taskID int64) ([]string, error) { | ||
var keys []string | ||
return keys, db.GetEngine(ctx).Table(ActionTaskOutput{}).Where("task_id=?", taskID).Cols("output_key").Find(&keys) | ||
} | ||
|
||
// InsertTaskOutputIfNotExist inserts a new task output if it does not exist. | ||
func InsertTaskOutputIfNotExist(ctx context.Context, taskID int64, key, value string) error { | ||
return db.WithTx(ctx, func(ctx context.Context) error { | ||
sess := db.GetEngine(ctx) | ||
if exist, err := sess.Exist(&ActionTaskOutput{TaskID: taskID, OutputKey: key}); err != nil { | ||
return err | ||
} else if exist { | ||
return nil | ||
} | ||
_, err := sess.Insert(&ActionTaskOutput{ | ||
TaskID: taskID, | ||
OutputKey: key, | ||
OutputValue: value, | ||
}) | ||
return err | ||
}) | ||
} |
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,18 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_20 //nolint | ||
|
||
import ( | ||
"xorm.io/xorm" | ||
) | ||
|
||
func AddActionTaskOutputTable(x *xorm.Engine) error { | ||
type ActionTaskOutput struct { | ||
ID int64 | ||
TaskID int64 `xorm:"INDEX UNIQUE(task_id_output_key)"` | ||
OutputKey string `xorm:"VARCHAR(255) UNIQUE(task_id_output_key)"` | ||
OutputValue string `xorm:"MEDIUMTEXT"` | ||
} | ||
return x.Sync(new(ActionTaskOutput)) | ||
} |
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