Skip to content

Commit 8eff29a

Browse files
committed
Simplifies docker workflow. Over-complicates mirror workflow
1 parent 006c2ab commit 8eff29a

File tree

2 files changed

+57
-18
lines changed

2 files changed

+57
-18
lines changed

.github/workflows/docker.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,21 @@ jobs:
4747
run: |
4848
TAGS=""
4949
50-
# Convert repo name to lowercase for Docker Hub
51-
REPO_LOWER=$(echo "${{ env.REPO_NAME }}" | tr '[:upper:]' '[:lower:]')
52-
5350
if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ inputs.tag }}" ]]; then
5451
# Manual dispatch with custom tag
5552
TAG="${{ inputs.tag }}"
56-
TAGS="docker.io/${REPO_LOWER}:${TAG},ghcr.io/${REPO_LOWER}:${TAG}"
53+
TAGS="docker.io/${{ env.REPO_NAME }}:${TAG},ghcr.io/${{ env.REPO_NAME }}:${TAG}"
5754
elif [[ "${{ github.ref_type }}" == "tag" ]]; then
5855
# Git tag push
5956
TAG="${{ github.ref_name }}"
6057
TAG="${TAG#v}" # Remove v prefix
61-
TAGS="docker.io/${REPO_LOWER}:${TAG},ghcr.io/${REPO_LOWER}:${TAG}"
58+
TAGS="docker.io/${{ env.REPO_NAME }}:${TAG},ghcr.io/${{ env.REPO_NAME }}:${TAG}"
6259
elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
6360
# Main branch push
64-
TAGS="docker.io/${REPO_LOWER}:latest,ghcr.io/${REPO_LOWER}:latest"
61+
TAGS="docker.io/${{ env.REPO_NAME }}:latest,ghcr.io/${{ env.REPO_NAME }}:latest"
6562
fi
6663
6764
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
68-
echo "repo_lower=${REPO_LOWER}" >> $GITHUB_OUTPUT
6965
echo "Publishing tags: ${TAGS}"
7066
7167
- name: 🔑 Login to Docker Hub
@@ -87,7 +83,7 @@ jobs:
8783
id: meta
8884
uses: docker/metadata-action@v5
8985
with:
90-
images: ghcr.io/${{ steps.tags.outputs.repo_lower }}
86+
images: ghcr.io/${{ env.REPO_NAME }}
9187
tags: |
9288
type=raw,value=${{ steps.tags.outputs.tags }}
9389
labels: |

.github/workflows/mirror.yml

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,32 @@
55
# - MIRROR_HOST: (optional) Hostname of target Git server, defaults to Codeberg
66
# - MIRROR_USER: (optional) User or org name of target repo, defaults to alicia
77
# - MIRROR_REPO: (optional) Name of target repo, defaults to same as source repo
8+
#
9+
# The workflow is triggered:
10+
# 1. weekly (at 01:30 on Sunday mornings) via a cron
11+
# 2. Whenever a new tagged version is published to git
12+
# 4. Or, can be triggered manually via the "Run workflow" button
813

914
name: 🪞 Mirror to Codeberg
1015

1116
on:
12-
workflow_dispatch:
1317
schedule:
1418
- cron: '30 01 * * 0'
1519
push:
1620
tags: [ 'v*' ]
21+
workflow_dispatch:
22+
inputs:
23+
host: { description: 'Git host (default: git@codeberg.org)' }
24+
user: { description: 'Git user/org name (default: current repo owner)' }
25+
repo: { description: 'Repository name (default: current repo name)' }
1726

1827
jobs:
1928
codeberg:
2029
runs-on: ubuntu-latest
21-
env: # Get values for target repo from env vars or fallback to defaults
22-
MIRROR_HOST: ${{ vars.MIRROR_HOST || 'git@codeberg.org' }}
23-
MIRROR_USER: ${{ vars.MIRROR_USER || 'alicia' }}
24-
MIRROR_REPO: ${{ vars.MIRROR_REPO || github.event.repository.name }}
30+
env: # Get values for target repo from inputs, env vars, or fallback to defaults
31+
MIRROR_HOST: ${{ inputs.host || vars.MIRROR_HOST || 'git@codeberg.org' }}
32+
MIRROR_USER: ${{ inputs.user || vars.MIRROR_USER || 'alicia' }}
33+
MIRROR_REPO: ${{ inputs.repo || vars.MIRROR_REPO || github.event.repository.name }}
2534
HAS_SSH: ${{ secrets.MIRROR_SSH != '' }}
2635
steps:
2736
- name: Cancel if SSH key not set
@@ -33,12 +42,46 @@ jobs:
3342
with: { fetch-depth: 0 }
3443

3544
- name: Mirror repository to target
45+
id: mirror
3646
run: |
37-
set -e
47+
set -euo pipefail
48+
LOG="$RUNNER_TEMP/mirror.log"
49+
50+
# Derive host from MIRROR_HOST (handles git@host, ssh://git@host:22, etc.)
51+
HOST="${{ env.MIRROR_HOST }}"
52+
HOST="${HOST#*://}"; HOST="${HOST#*@}"; HOST="${HOST%%:*}"
53+
3854
mkdir -p ~/.ssh
3955
echo "${{ secrets.MIRROR_SSH }}" > ~/.ssh/id_rsa
4056
chmod 600 ~/.ssh/id_rsa
41-
ssh-keyscan codeberg.org >> ~/.ssh/known_hosts
42-
git remote add mirror ${{ env.MIRROR_HOST }}:${{ env.MIRROR_USER }}/${{ env.MIRROR_REPO }}.git || true
43-
git push mirror --all
44-
git push mirror --tags
57+
ssh-keyscan "$HOST" >> ~/.ssh/known_hosts 2>/dev/null || true
58+
{
59+
git remote add mirror ${{ env.MIRROR_HOST }}:${{ env.MIRROR_USER }}/${{ env.MIRROR_REPO }}.git || true
60+
git push mirror --all
61+
git push mirror --tags
62+
} |& tee "$LOG"
63+
64+
- name: Summarize
65+
if: always()
66+
continue-on-error: true
67+
run: |
68+
LOG="$RUNNER_TEMP/mirror.log"
69+
TARGET="${{ env.MIRROR_HOST }}:${{ env.MIRROR_USER }}/${{ env.MIRROR_REPO }}.git"
70+
if [ "${{ env.HAS_SSH }}" != "true" ]; then
71+
{
72+
echo "🚫 **Cancelled, because no SSH key was set**.<br>"
73+
echo "_Looks like you forgot to set the \`MIRROR_SSH\` secret to your encrypted private key?_"
74+
} >> "$GITHUB_STEP_SUMMARY"; exit 0
75+
fi
76+
if [ "${{ steps.mirror.outcome }}" = "success" ]; then
77+
{
78+
echo "✅ **Completed**.<br>_You can now access the repository at_ \`${TARGET}\` 🥳"
79+
echo; echo '```'; (tail -n 200 "$LOG" || true); echo '```'
80+
} >> "$GITHUB_STEP_SUMMARY"
81+
else
82+
{
83+
echo "❌ **Failed**.<br>_Because the mirror push did not complete successfully._"
84+
echo; echo '```'; ([ -f "$LOG" ] && tail -n 200 "$LOG" || echo "No log output captured."); echo '```'
85+
} >> "$GITHUB_STEP_SUMMARY"
86+
fi
87+

0 commit comments

Comments
 (0)