Featuer/gitops extra command #47
@@ -53,12 +53,20 @@ jobs:
|
|||||||
ID=$(date +%s | md5sum | head -c 8)
|
ID=$(date +%s | md5sum | head -c 8)
|
||||||
echo "dispatch_id=$ID" >> "$GITHUB_OUTPUT"
|
echo "dispatch_id=$ID" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Resolve commit author
|
||||||
|
id: author
|
||||||
|
run: |
|
||||||
|
echo "name=$(git log -1 --format='%an')" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "email=$(git log -1 --format='%ae')" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Dispatch to GitOps repo
|
- name: Dispatch to GitOps repo
|
||||||
env:
|
env:
|
||||||
GITEA_TOKEN: ${{ secrets.GITOPS_DISPATCH_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.GITOPS_DISPATCH_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
INPUTS=$(jq -nc \
|
INPUTS=$(jq -nc \
|
||||||
--arg dispatch_id "${{ steps.gen.outputs.dispatch_id }}" \
|
--arg dispatch_id "${{ steps.gen.outputs.dispatch_id }}" \
|
||||||
|
--arg author_name "${{ steps.author.outputs.name }}" \
|
||||||
|
--arg author_email "${{ steps.author.outputs.email }}" \
|
||||||
--arg file "$GITOPS_FILE" \
|
--arg file "$GITOPS_FILE" \
|
||||||
--arg yq_tpl "$GITOPS_YQ_TPL" \
|
--arg yq_tpl "$GITOPS_YQ_TPL" \
|
||||||
--arg version "$GITOPS_VERSION" \
|
--arg version "$GITOPS_VERSION" \
|
||||||
@@ -66,7 +74,7 @@ jobs:
|
|||||||
--arg source_commit "$GITOPS_SOURCE_COMMIT" \
|
--arg source_commit "$GITOPS_SOURCE_COMMIT" \
|
||||||
--arg git_tag_prefix "${GITOPS_TAG_PREFIX:-}" \
|
--arg git_tag_prefix "${GITOPS_TAG_PREFIX:-}" \
|
||||||
--arg extra_cmd "${GITOPS_EXTRA_CMD:-}" \
|
--arg extra_cmd "${GITOPS_EXTRA_CMD:-}" \
|
||||||
'{dispatch_id: $dispatch_id, file: $file, yq_tpl: $yq_tpl, version: $version, source_repo: $source_repo, source_commit: $source_commit, git_tag_prefix: $git_tag_prefix, extra_cmd: $extra_cmd}')
|
'{dispatch_id: $dispatch_id, author_name: $author_name, author_email: $author_email, file: $file, yq_tpl: $yq_tpl, version: $version, source_repo: $source_repo, source_commit: $source_commit, git_tag_prefix: $git_tag_prefix, extra_cmd: $extra_cmd}')
|
||||||
curl -s -X POST \
|
curl -s -X POST \
|
||||||
"${GITEA_API_URL}/api/v1/repos/${GITOPS_REPO}/actions/workflows/${GITOPS_WORKFLOW}/dispatches" \
|
"${GITEA_API_URL}/api/v1/repos/${GITOPS_REPO}/actions/workflows/${GITOPS_WORKFLOW}/dispatches" \
|
||||||
-H "Authorization: token $GITEA_TOKEN" \
|
-H "Authorization: token $GITEA_TOKEN" \
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ INPUTS=$(jq -nc \
|
|||||||
--arg source_commit "$GITOPS_SOURCE_COMMIT" \
|
--arg source_commit "$GITOPS_SOURCE_COMMIT" \
|
||||||
--arg git_tag_prefix "${GITOPS_TAG_PREFIX:-}" \
|
--arg git_tag_prefix "${GITOPS_TAG_PREFIX:-}" \
|
||||||
--arg extra_cmd "${GITOPS_EXTRA_CMD:-}" \
|
--arg extra_cmd "${GITOPS_EXTRA_CMD:-}" \
|
||||||
'{file: $file, yq_tpl: $yq_tpl, version: $version, source_repo: $source_repo, source_commit: $source_commit, git_tag_prefix: $git_tag_prefix, extra_cmd: $extra_cmd}')
|
--arg author_name "${GIT_USER_NAME:-}" \
|
||||||
|
--arg author_email "${GIT_USER_EMAIL:-}" \
|
||||||
|
'{file: $file, yq_tpl: $yq_tpl, version: $version, source_repo: $source_repo, source_commit: $source_commit, git_tag_prefix: $git_tag_prefix, extra_cmd: $extra_cmd, author_name: $author_name, author_email: $author_email}')
|
||||||
|
|
||||||
DIR="$(cd "$(dirname "$0")" && pwd)"
|
DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
echo "gitops-dispatch: dispatching to $GITOPS_REPO/$GITOPS_WORKFLOW..."
|
echo "gitops-dispatch: dispatching to $GITOPS_REPO/$GITOPS_WORKFLOW..."
|
||||||
|
|||||||
@@ -98,8 +98,8 @@ _gitops_update() {
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git -c user.name="gitea-ci-bot" \
|
git -c user.name="${GIT_USER_NAME:-gitea-ci-bot}" \
|
||||||
-c user.email="ci@keskikuja.site" \
|
-c user.email="${GIT_USER_EMAIL:-ci@keskikuja.site}" \
|
||||||
commit -m "[skip ci] gitops: update version to ${VERSION}" || _gitops_fail "Failed to commit"
|
commit -m "[skip ci] gitops: update version to ${VERSION}" || _gitops_fail "Failed to commit"
|
||||||
GITOPS_SHA="$(git rev-parse HEAD)"
|
GITOPS_SHA="$(git rev-parse HEAD)"
|
||||||
git push || _gitops_fail "Failed to push"
|
git push || _gitops_fail "Failed to push"
|
||||||
|
|||||||
@@ -59,6 +59,12 @@ on:
|
|||||||
extra_cmd:
|
extra_cmd:
|
||||||
required: false
|
required: false
|
||||||
type: string
|
type: string
|
||||||
|
author_name:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
author_email:
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
|
||||||
env:
|
env:
|
||||||
INPUT_FILE: ${{ inputs.file }}
|
INPUT_FILE: ${{ inputs.file }}
|
||||||
@@ -70,6 +76,8 @@ env:
|
|||||||
GITEA_API_URL: ${{ gitea.server_url }}
|
GITEA_API_URL: ${{ gitea.server_url }}
|
||||||
GIT_TAG_PREFIX: ${{ inputs.git_tag_prefix || '' }}
|
GIT_TAG_PREFIX: ${{ inputs.git_tag_prefix || '' }}
|
||||||
GITOPS_EXTRA_CMD: ${{ inputs.extra_cmd || '' }}
|
GITOPS_EXTRA_CMD: ${{ inputs.extra_cmd || '' }}
|
||||||
|
GIT_USER_NAME: ${{ inputs.author_name || '' }}
|
||||||
|
GIT_USER_EMAIL: ${{ inputs.author_email || '' }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update:
|
update:
|
||||||
@@ -153,6 +161,8 @@ gitops-update:
|
|||||||
|
|
||||||
When `GITOPS_EXTRA_CMD` is set, the script runs it after `yq` and stages all changes (`git add -A`) instead of only the input file — so any files generated by the extra command (e.g. `Chart.lock`, `charts/`) are included in the commit.
|
When `GITOPS_EXTRA_CMD` is set, the script runs it after `yq` and stages all changes (`git add -A`) instead of only the input file — so any files generated by the extra command (e.g. `Chart.lock`, `charts/`) are included in the commit.
|
||||||
|
|
||||||
|
By default the GitOps commit is made as `gitea-ci-bot`. To use the original commit author instead, the dispatch workflow resolves it automatically from the consumer repo — no extra config needed. Just ensure the GitOps repo's `gitops-service.yaml` template has the `author_name` and `author_email` inputs and env mappings.
|
||||||
|
|
||||||
### 2.3 Parameters
|
### 2.3 Parameters
|
||||||
|
|
||||||
| Input | Required | Description |
|
| Input | Required | Description |
|
||||||
|
|||||||
Reference in New Issue
Block a user