Sync our 'head' with upstream HEAD #5775
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
name: "Sync our 'head' with upstream HEAD" | |
on: | |
schedule: | |
- cron: '42/64 * * * *' | |
push: | |
paths: | |
- .github/workflows/head--upstream-sync.yml | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow_ref }} | |
jobs: | |
pull: | |
name: Sync with upstream | |
runs-on: ubuntu-latest | |
environment: upstream-head-sync | |
permissions: | |
contents: write | |
defaults: | |
run: | |
# -o verbose -o xtrace | |
shell: bash --noprofile --norc -o errexit -o pipefail -o nounset {0} | |
env: | |
UPSTREAM_SYNC_REMOTE_URL: ${{ vars.UPSTREAM_SYNC_REMOTE_URL || 'UNBOUND_VARIABLE' }} | |
UPSTREAM_SYNC_REMOTE_NAME: upstream | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: 'head' | |
sparse-checkout: '.' | |
- name: Config | |
run: | | |
export RUN_N_LOG_DIR="$HOME/git-logs" | |
printf "RUN_N_LOG_DIR=%s\n" "${RUN_N_LOG_DIR}" >> "${GITHUB_ENV}" | |
mkdir -vp "${RUN_N_LOG_DIR}" | |
run_n_log() { | |
local basepath="${RUN_N_LOG_DIR}/$(date +%s%N).$(basename "${1}")" | |
local cmd_log="${basepath}.cmd.log" | |
local summary_log="${basepath}.summary.log" | |
local stdout_log="${basepath}.stdout.log" | |
local stderr_log="${basepath}.stderr.log" | |
local cmd_str=$( python -c 'import sys,shlex; print(*[shlex.quote(s) for s in sys.argv[1:]], end="")' "${@}" ) | |
printf "%s" "${cmd_str}" > "${cmd_log}" | |
printf "%s\n" "${cmd_str}" | |
printf "<details><summary><code>%s</code></summary>\n" "${cmd_str}" >> "${summary_log}" | |
printf '\n```console\n' >> "${summary_log}" # codeblock requires blank line before | |
printf "git@actions> %s\n" "${cmd_str}" >> "${summary_log}" | |
"${@}" > >(tee -a "${stdout_log}" "${summary_log}") 2> >(tee -a "${stderr_log}" "${summary_log}") | |
sleep 0.1 || true # wait for all the subshells to stop writing to files | |
printf '\n```\n</details>\n' >> "${summary_log}" | |
} | |
declare -p -f > ~/funcs.sh | |
- name: Add remote | |
run: | | |
source ~/funcs.sh | |
[[ -n "${UPSTREAM_SYNC_REMOTE_NAME}" ]] | |
[[ -n "${UPSTREAM_SYNC_REMOTE_URL}" ]] | |
run_n_log git remote add "${UPSTREAM_SYNC_REMOTE_NAME}" "${UPSTREAM_SYNC_REMOTE_URL}" | |
run_n_log git remote --verbose || true | |
run_n_log git remote show "${UPSTREAM_SYNC_REMOTE_NAME}" || true | |
run_n_log git config --show-scope --get-regexp ^ 2>&1 | sed 's/^/::debug::/' || true | |
- name: Pull | |
run: | | |
source ~/funcs.sh | |
[[ -n "${UPSTREAM_SYNC_REMOTE_NAME}" ]] | |
run_n_log git pull "${UPSTREAM_SYNC_REMOTE_NAME}" "HEAD" | |
- name: Push | |
run: | | |
source ~/funcs.sh | |
run_n_log git push origin "head" | |
- name: Summary | |
if: ${{ always() }} | |
continue-on-error: true | |
run: | | |
# | sed 's/^/::warning title=::/' | |
# TODO parse log files and produce summary | |
cat "${RUN_N_LOG_DIR}"/*.summary.log >> "${GITHUB_STEP_SUMMARY}" | |