-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (80 loc) · 3.25 KB
/
Copy pathsync-code.yml
File metadata and controls
92 lines (80 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Sync Vendor Code
on:
pull_request:
paths:
- '.docker-socket-proxy-version'
concurrency:
group: sync-vendor-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
sync:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: read
if: |
github.event.pull_request.author_association == 'OWNER' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.author_association == 'COLLABORATOR' ||
(startsWith(github.head_ref, 'renovate/') && github.actor == 'renovate[bot]')
steps:
- name: Checkout PR branch
uses: actions/checkout@v6
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Get Target Version
id: get_version
run: |
VERSION=$(cat .docker-socket-proxy-version)
echo "Target version from file: ${VERSION}"
# Validate version format (v + semver with optional pre-release/build metadata)
if ! [[ "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
echo "Error: Invalid version format in .docker-socket-proxy-version: $VERSION"
echo "Expected format: vX.Y.Z (e.g., v0.4.2) with optional pre-release (e.g., v0.5.0-rc.2) or build metadata"
exit 1
fi
echo "tag=${VERSION}" >> $GITHUB_OUTPUT
- name: Sync Source Code
run: |
set -euo pipefail
TARGET_DIR="docker-socket-proxy-src"
UPSTREAM_REPO="Tecnativa/docker-socket-proxy"
VERSION_TAG="${{ steps.get_version.outputs.tag }}"
echo "Cleaning old code from ${TARGET_DIR}"
rm -rf "${TARGET_DIR:?}"
mkdir -p "${TARGET_DIR}"
echo "Downloading source for tag ${VERSION_TAG} from ${UPSTREAM_REPO}"
TEMP_FILE=$(mktemp)
# Download with error handling
if ! curl -fsL "https://github.com/${UPSTREAM_REPO}/archive/refs/tags/${VERSION_TAG}.tar.gz" -o "$TEMP_FILE"; then
echo "Error: Failed to download source code for ${VERSION_TAG}"
rm -f "$TEMP_FILE"
exit 1
fi
# Extract with error handling
if ! tar -xzf "$TEMP_FILE" --strip-components=1 -C "${TARGET_DIR}"; then
echo "Error: Failed to extract source code"
rm -f "$TEMP_FILE"
exit 1
fi
rm -f "$TEMP_FILE"
# Verify critical files exist
if [[ ! -f "${TARGET_DIR}/Dockerfile" ]]; then
echo "Error: Dockerfile not found in extracted source"
exit 1
fi
echo "Source code successfully synced"
- name: Commit and Push Changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if git diff --quiet --exit-code; then
echo "No source code changes detected. Nothing to commit."
exit 0
fi
echo "Committing updated source code..."
git add docker-socket-proxy-src/
git commit -m "[Auto] Sync source code for ${{ steps.get_version.outputs.tag }}"
git push