Repository navigation
66 lines (57 loc) · 2 KB
/
Copy pathgit-mirror-checkout.yml
File metadata and controls
66 lines (57 loc) · 2 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
name: Git mirror checkout
on:
pull_request:
paths:
- "git-mirror-checkout/**"
- ".github/workflows/git-mirror-checkout.yml"
push:
branches:
- main
paths:
- "git-mirror-checkout/**"
- ".github/workflows/git-mirror-checkout.yml"
permissions:
contents: read
jobs:
mirror:
runs-on: ubuntu-latest
steps:
- name: Check out the action
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
path: action
# One branch under a name HEAD does not point at, as a mirror that fetches one branch has.
- name: Make a mirror
run: |
git init --quiet --bare --initial-branch=unborn "$RUNNER_TEMP/mirror.git"
git -C "$RUNNER_TEMP/mirror.git" fetch --quiet --no-tags "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" "+HEAD:refs/heads/main"
- id: checkout
uses: ./action/git-mirror-checkout
with:
mirror: ${{ runner.temp }}/mirror.git
- name: Check the workspace borrows from the mirror
env:
SOURCE: ${{ steps.checkout.outputs.source }}
run: |
test "$SOURCE" = mirror
test "$(git rev-parse HEAD)" = "$GITHUB_SHA"
grep -qF "$RUNNER_TEMP/mirror.git/objects" .git/objects/info/alternates
test "$(git rev-list --count HEAD)" -gt 1
git fetch --quiet origin main
# The fallback cleans the workspace, so the action under test sits in a checkout it keeps.
fallback:
runs-on: ubuntu-latest
steps:
- name: Check out the action
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- id: checkout
uses: ./git-mirror-checkout
with:
mirror: ${{ runner.temp }}/missing.git
- name: Check actions/checkout ran
env:
SOURCE: ${{ steps.checkout.outputs.source }}
run: |
test "$SOURCE" = checkout
test "$(git rev-parse HEAD)" = "$GITHUB_SHA"
test ! -e .git/objects/info/alternates