Code Issues Pull Requests Actions Packages Projects Releases 15 Wiki Activity Security Code Quality
2 Commits
2 changed files with 54 additions and 7 deletions

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
# Actions
## load-env
Copy các biến môi trường có sẵn trong process của runner vào env của job. Bước phía sau đọc được bằng `${{ env.TÊN }}`.
Biến khai báo trên runner không tự vào context `env`. Context đó chỉ chứa biến do workflow đặt. Action đọc biến trong process, ghi vào `$GITHUB_ENV`, và mask giá trị trong log.
### Usage
```yaml
- uses: https://git.sothink.vn/gitea/global-workflow/.gitea/actions/load-env@main
with:
names: RELEASE_TOKEN DT_API_KEY
- name: Use the loaded values
run: echo "token length ${#RELEASE_TOKEN}"
env:
API_KEY: ${{ env.DT_API_KEY }}
```
`names` là danh sách tên, cách nhau bởi khoảng trắng, load đúng thứ tự đó. Trong repo này, workflow release load `GITHUB_TOKEN RELEASE_TOKEN`; workflow quét lỗ hổng load `DT_API_KEY`.
Cùng repo, sau khi đã checkout, có thể gọi local:
```yaml
- uses: ./.gitea/actions/load-env
with:
names: RELEASE_TOKEN
```
Scoped workflow chạy trên repo khác thì không dùng `uses: ./`. Checkout của repo đó không có action này. Dùng URL đầy đủ ở trên. Ref `@main` lấy code trên nhánh mặc định, nên action phải được push lên `main` trước khi workflow khác gọi.
### Inputs
| Input | Bắt buộc | Mặc định | Ý nghĩa |
|---|---|---|---|
| `names` | có | | Tên biến, cách nhau bởi khoảng trắng. Chỉ nhận `[A-Za-z_][A-Za-z0-9_]*`. |
| `required` | không | `true` | `true`: thiếu hoặc rỗng thì dừng job. `false`: bỏ qua biến không có và in `Skipping unset …`. |
### Biến phải có trong container của job
act_runner không đưa env của máy host vào container trừ khi khai báo trong cấu hình runner:
```yaml
runner:
envs:
RELEASE_TOKEN: "…"
DT_API_KEY: "…"
```
Thiếu biến, với `required: true`, log có dòng `<TÊN> is not set on this runner`.
+2 -7
View File
@@ -43,10 +43,10 @@ jobs:
curl --silent --show-error --fail --location --output cliff.toml "$url"
echo "config=cliff.toml" >> "$GITHUB_OUTPUT"
- name: Read GITHUB_TOKEN from the runner
- name: Read envs from the runner
uses: https://git.sothink.vn/gitea/global-workflow/.gitea/actions/load-env@main
with:
names: GITHUB_TOKEN
names: GITHUB_TOKEN RELEASE_TOKEN
# Gitea's GITHUB_TOKEN is rejected by api.github.com. Pass a github.com PAT instead.
- name: Generate release notes
@@ -58,11 +58,6 @@ jobs:
env:
OUTPUT: release-notes.md
- name: Read Release Token from the runner
uses: https://git.sothink.vn/gitea/global-workflow/.gitea/actions/load-env@main
with:
names: RELEASE_TOKEN
- name: Create release
uses: softprops/action-gh-release@v3
with: