Skip to content

Commit 241f5d6

Browse files
fix: action-commit-push again (#34)
Co-authored-by: ChristophShyper <45788587+ChristophShyper@users.noreply.github.com>
1 parent b748ca3 commit 241f5d6

1 file changed

Lines changed: 49 additions & 34 deletions

File tree

.github/workflows/e2e-action-commit-push.yml

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,6 @@ jobs:
311311
needs: [preflight]
312312
runs-on: ubuntu-latest
313313
steps:
314-
- name: Checkout repository
315-
uses: actions/checkout@v6
316-
with:
317-
fetch-depth: 0
318-
path: repo
319-
320314
- name: Checkout action source for ref-mode validation
321315
if: ${{ inputs.mode == 'ref' }}
322316
uses: actions/checkout@v6
@@ -325,20 +319,56 @@ jobs:
325319
ref: ${{ inputs.action_ref }}
326320
path: action-src
327321

328-
- name: Create test file
329-
run: echo "E2E identity override test $(date -u)" > repo/e2e-identity-override.md
322+
- name: Prepare local repository
323+
if: ${{ inputs.mode == 'ref' }}
324+
run: |
325+
set -euo pipefail
326+
rm -rf "${RUNNER_TEMP}/identity-ws" "${RUNNER_TEMP}/identity-remote.git" "${RUNNER_TEMP}/identity-output.txt" "${RUNNER_TEMP}/identity-bin"
327+
mkdir -p "${RUNNER_TEMP}/identity-ws" "${RUNNER_TEMP}/identity-bin"
328+
git init "${RUNNER_TEMP}/identity-ws"
329+
git -C "${RUNNER_TEMP}/identity-ws" branch -m master
330+
git -C "${RUNNER_TEMP}/identity-ws" config user.name init
331+
git -C "${RUNNER_TEMP}/identity-ws" config user.email init@example.com
332+
touch "${RUNNER_TEMP}/identity-ws/.keep"
333+
git -C "${RUNNER_TEMP}/identity-ws" add .
334+
git -C "${RUNNER_TEMP}/identity-ws" commit -m init
335+
git init --bare "${RUNNER_TEMP}/identity-remote.git"
336+
git -C "${RUNNER_TEMP}/identity-ws" remote add origin "${RUNNER_TEMP}/identity-remote.git"
337+
echo "E2E identity override test $(date -u)" > "${RUNNER_TEMP}/identity-ws/e2e-identity-override.md"
338+
real_git="$(command -v git)"
339+
cat > "${RUNNER_TEMP}/identity-bin/git" <<EOF
340+
#!/bin/sh
341+
if [ "\$1" = "push" ]; then
342+
exit 0
343+
fi
344+
exec "${real_git}" "\$@"
345+
EOF
346+
chmod +x "${RUNNER_TEMP}/identity-bin/git"
347+
348+
- name: Build action image from source
349+
if: ${{ inputs.mode == 'ref' }}
350+
run: docker build -t triglav-action-commit-push:test ./action-src
330351

331352
- name: Commit with custom identity
332353
if: ${{ inputs.mode == 'ref' }}
333-
id: commit
334-
uses: ./action-src
335-
with:
336-
github_token: ${{ secrets.GITHUB_TOKEN }}
337-
commit_message: "test(commit-push): custom identity test"
338-
target_branch: test/e2e-commit-push-identity-${{ github.run_id }}
339-
repository_path: repo
340-
user_name: "Release Automation"
341-
user_email: "release-bot@example.com"
354+
run: |
355+
set -euo pipefail
356+
docker run --rm \
357+
-v "${RUNNER_TEMP}:/github/workspace" \
358+
-v "${RUNNER_TEMP}:/github/runner_temp" \
359+
-w /github/workspace \
360+
-e PATH="/github/workspace/identity-bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
361+
-e GITHUB_WORKSPACE=/github/workspace/identity-ws \
362+
-e GITHUB_ACTOR="${{ github.actor }}" \
363+
-e GITHUB_REPOSITORY=owner/repo \
364+
-e GITHUB_TOKEN=fake \
365+
-e GITHUB_OUTPUT=/github/runner_temp/identity-output.txt \
366+
-e INPUT_ORGANIZATION_DOMAIN=github.com \
367+
-e INPUT_COMMIT_MESSAGE="test(commit-push): custom identity test" \
368+
-e INPUT_REPOSITORY_PATH=. \
369+
-e INPUT_USER_NAME="Release Automation" \
370+
-e INPUT_USER_EMAIL="release-bot@example.com" \
371+
triglav-action-commit-push:test
342372
343373
- name: Commit via docker image (preview)
344374
if: ${{ inputs.mode == 'image' }}
@@ -353,29 +383,14 @@ jobs:
353383
- name: Verify commit identity
354384
if: ${{ inputs.mode == 'ref' }}
355385
run: |
356-
sudo chown -R "$(id -u):$(id -g)" repo
357-
cd repo
358-
branch="test/e2e-commit-push-identity-${{ github.run_id }}"
359-
local_sha="$(git rev-parse HEAD)"
360-
git fetch origin "${branch}"
361-
remote_sha="$(git rev-parse FETCH_HEAD)"
362-
test "${local_sha}" = "${remote_sha}"
386+
sudo chown -R "$(id -u):$(id -g)" "${RUNNER_TEMP}/identity-ws"
387+
cd "${RUNNER_TEMP}/identity-ws"
363388
git log -1 --format='author=%an <%ae>%ncommitter=%cn <%ce>' HEAD
364389
test "$(git log -1 --format=%an HEAD)" = "Release Automation"
365390
test "$(git log -1 --format=%ae HEAD)" = "release-bot@example.com"
366391
test "$(git log -1 --format=%cn HEAD)" = "Release Automation"
367392
test "$(git log -1 --format=%ce HEAD)" = "release-bot@example.com"
368393
369-
- name: Cleanup - delete test branch
370-
if: ${{ always() && inputs.mode == 'ref' }}
371-
run: |
372-
sudo chown -R "$(id -u):$(id -g)" repo || true
373-
cd repo
374-
branch="test/e2e-commit-push-identity-${{ github.run_id }}"
375-
if git ls-remote --exit-code --heads origin "${branch}" >/dev/null 2>&1; then
376-
git push origin --delete "${branch}"
377-
fi
378-
379394
reset-target-branch-to-base:
380395
name: Reset target branch to base branch
381396
needs: [preflight]

0 commit comments

Comments
 (0)