Compare commits
25
Commits
v2.0.0
...
92d9773998
No files matched your search
@@ -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`.
|
||||
@@ -0,0 +1,51 @@
|
||||
name: Load runner environment
|
||||
description: Copy named variables from the runner process into the job env context.
|
||||
|
||||
inputs:
|
||||
names:
|
||||
description: Space-separated variable names, loaded in the given order.
|
||||
required: true
|
||||
required:
|
||||
description: Fail when a named variable is missing or empty.
|
||||
required: false
|
||||
default: "true"
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Load runner environment
|
||||
shell: bash
|
||||
env:
|
||||
LOAD_ENV_NAMES: ${{ inputs.names }}
|
||||
LOAD_ENV_REQUIRED: ${{ inputs.required }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [[ -z "${LOAD_ENV_NAMES// }" ]]; then
|
||||
echo "No environment variable names were given"
|
||||
exit 1
|
||||
fi
|
||||
for name in $LOAD_ENV_NAMES; do
|
||||
if [[ ! "$name" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then
|
||||
echo "Invalid environment variable name: ${name}"
|
||||
exit 1
|
||||
fi
|
||||
value="${!name-}"
|
||||
if [[ -z "$value" ]]; then
|
||||
if [[ "${LOAD_ENV_REQUIRED}" == "true" ]]; then
|
||||
echo "${name} is not set on this runner"
|
||||
exit 1
|
||||
fi
|
||||
echo "Skipping unset ${name}"
|
||||
continue
|
||||
fi
|
||||
if [[ "$value" != *$'\n'* ]]; then
|
||||
echo "::add-mask::${value}"
|
||||
fi
|
||||
delimiter="LOAD_ENV_${name}_${RANDOM}_$$"
|
||||
{
|
||||
printf '%s<<%s\n' "$name" "$delimiter"
|
||||
printf '%s\n' "$value"
|
||||
printf '%s\n' "$delimiter"
|
||||
} >> "$GITHUB_ENV"
|
||||
echo "Loaded ${name} from the runner"
|
||||
done
|
||||
@@ -0,0 +1,68 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*.*.*"
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
releases: write
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
name: Release
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
# Local config wins, in this order. Download the shared file only when none exist.
|
||||
- name: Resolve cliff.toml
|
||||
id: cliff-config
|
||||
env:
|
||||
CLIFF_REPO: ${{ vars.CLIFF_CONFIG_REPO || 'gitea/global-workflow' }}
|
||||
CLIFF_CONFIGS: cliff.toml .github/cliff.toml .gitea/cliff.toml
|
||||
run: |
|
||||
set -euo pipefail
|
||||
for candidate in $CLIFF_CONFIGS; do
|
||||
if [[ -f "$candidate" ]]; then
|
||||
echo "Using ${candidate} from this repository"
|
||||
echo "config=${candidate}" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
url="${GITHUB_API_URL}/repos/${CLIFF_REPO}/raw/cliff.toml?ref=main"
|
||||
echo "No local cliff.toml; fetching ${url}"
|
||||
curl --silent --show-error --fail --location --output cliff.toml "$url"
|
||||
echo "config=cliff.toml" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Read envs from the runner
|
||||
uses: https://git.sothink.vn/gitea/global-workflow/.gitea/actions/load-env@main
|
||||
with:
|
||||
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
|
||||
uses: orhun/git-cliff-action@v4
|
||||
with:
|
||||
config: ${{ steps.cliff-config.outputs.config }}
|
||||
args: --latest --strip header
|
||||
github_token: ${{ env.GITHUB_TOKEN }}
|
||||
env:
|
||||
OUTPUT: release-notes.md
|
||||
|
||||
- name: Create release
|
||||
uses: softprops/action-gh-release@v3
|
||||
with:
|
||||
# prerelease only when the tag contains "-alpha", "-beta" or "-rc". ex: v1.0.0-alpha.1, v1.0.0-beta.1, v1.0.0-rc.1
|
||||
prerelease: ${{ contains(github.ref, '-alpha') || contains(github.ref, '-beta') || contains(github.ref, '-rc') }}
|
||||
body_path: release-notes.md
|
||||
token: ${{ env.RELEASE_TOKEN }} # Use this token if you want user author is 'github-actions' bot
|
||||
draft: false
|
||||
@@ -21,11 +21,16 @@ jobs:
|
||||
output-file: sbom.json
|
||||
upload-artifact: false
|
||||
|
||||
- name: Read API key from the runner
|
||||
uses: https://git.sothink.vn/gitea/global-workflow/.gitea/actions/load-env@main
|
||||
with:
|
||||
names: DT_API_KEY
|
||||
|
||||
- name: Upload SBOM to Dependency-Track
|
||||
uses: DependencyTrack/gh-upload-sbom@v4
|
||||
with:
|
||||
server-hostname: "${{ vars.DT_HOSTNAME }}"
|
||||
api-key: "${{ secrets.DT_API_KEY }}"
|
||||
api-key: ${{ env.DT_API_KEY }}
|
||||
project-name: "${{ github.repository }}"
|
||||
project-version: "latest"
|
||||
bom-filename: "sbom.json"
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "**"
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
name: Release
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
# Gitea's GITHUB_TOKEN is rejected by api.github.com. Pass a github.com PAT instead.
|
||||
- name: Generate release notes
|
||||
uses: orhun/git-cliff-action@v4
|
||||
with:
|
||||
config: cliff.toml
|
||||
args: --latest --strip header
|
||||
github_token: ${{ secrets.PAT_GITHUB }}
|
||||
env:
|
||||
OUTPUT: release-notes.md
|
||||
|
||||
- name: Create release
|
||||
uses: softprops/action-gh-release@v3
|
||||
with:
|
||||
token: ${{ secrets.RELEASE_TOKEN }}
|
||||
prerelease: ${{ contains(github.ref, '-alpha') || contains(github.ref, '-beta') || contains(github.ref, '-rc') }}
|
||||
body_path: release-notes.md
|
||||
+11
-4
@@ -25,11 +25,18 @@ body = """
|
||||
- {% if commit.scope %}**{{ commit.scope }}**: {% endif %}{{ commit.message | upper_first }} ({{ commit.id | truncate(length=7, end="") }})
|
||||
{%- endfor %}
|
||||
{% endfor %}
|
||||
{%- set authors = commits | map(attribute="author.name") | unique | sort %}
|
||||
{% if authors | length > 0 %}
|
||||
{#- Author names vary per machine (tienbh / Tien-BH / ...); the email local part matches the Gitea username. -#}
|
||||
{%- set_global usernames = [] %}
|
||||
{%- for commit in commits %}
|
||||
{%- set username = commit.author.email | split(pat="@") | first | lower %}
|
||||
{%- if username and username is not containing("bot") and username != "github-actions" and not username in usernames %}
|
||||
{%- set_global usernames = usernames | concat(with=username) %}
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
{% if usernames | length > 0 %}
|
||||
## Contributors
|
||||
{% for author in authors %}
|
||||
* {{ author }}
|
||||
{% for username in usernames | sort %}
|
||||
* @{{ username }}
|
||||
{%- endfor %}
|
||||
{% endif %}
|
||||
{% if server and repository and version %}
|
||||
|
||||
Reference in new issue
Block a user