70 lines
2.0 KiB
YAML
70 lines
2.0 KiB
YAML
name: Sync source to CNB
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- '**'
|
|
tags:
|
|
- '**'
|
|
delete:
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
concurrency:
|
|
group: sync-cnb-source-${{ github.event_name == 'delete' && format('{0}/{1}', github.event.ref_type, github.event.ref) || github.ref }}
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
sync:
|
|
name: Sync Git ref
|
|
runs-on: ubuntu-24.04
|
|
timeout-minutes: 5
|
|
steps:
|
|
- name: Check out source
|
|
if: ${{ github.event_name != 'delete' }}
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 0
|
|
filter: blob:none
|
|
|
|
- name: Push Git ref to CNB
|
|
env:
|
|
CNB_REPO_URL_HTTPS: ${{ secrets.CNB_REPO_URL_HTTPS }}
|
|
CNB_TOKEN: ${{ secrets.CNB_TOKEN }}
|
|
CNB_TOKEN_USER_NAME: ${{ secrets.CNB_TOKEN_USER_NAME }}
|
|
DELETED_REF: ${{ github.event.ref }}
|
|
DELETED_REF_TYPE: ${{ github.event.ref_type }}
|
|
run: |
|
|
set -euo pipefail
|
|
if [[ -z "${CNB_TOKEN:-}" ]]; then
|
|
echo "CNB_TOKEN is not configured"
|
|
exit 1
|
|
fi
|
|
|
|
cnb_url="${CNB_REPO_URL_HTTPS:-https://cnb.cool/axlmc/Axolotl.git}"
|
|
token_user="${CNB_TOKEN_USER_NAME:-cnb}"
|
|
auth="$(printf '%s:%s' "$token_user" "$CNB_TOKEN" | base64 -w0)"
|
|
git_cnb() {
|
|
git -c "http.extraHeader=Authorization: Basic $auth" "$@"
|
|
}
|
|
|
|
if [[ "$GITHUB_EVENT_NAME" == "delete" ]]; then
|
|
git init
|
|
if [[ "$DELETED_REF_TYPE" == "tag" ]]; then
|
|
ref="refs/tags/$DELETED_REF"
|
|
else
|
|
ref="refs/heads/$DELETED_REF"
|
|
fi
|
|
git_cnb push "$cnb_url" --delete "$ref"
|
|
else
|
|
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
|
|
git fetch --force origin "$GITHUB_REF:$GITHUB_REF"
|
|
source_ref="$GITHUB_REF"
|
|
else
|
|
source_ref="HEAD"
|
|
fi
|
|
git_cnb push --force "$cnb_url" "$source_ref:$GITHUB_REF"
|
|
fi
|