Skip to content

Commit 6d6629f

Browse files
committed
Make a drop-in replacement for actions/checkout
1 parent 1e1d91e commit 6d6629f

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed

.github/workflows/test-checkout.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
name: Test the checkout action
3+
4+
on:
5+
push:
6+
branches:
7+
- '**'
8+
jobs:
9+
test-checkout:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: ./checkout@nickvolynkin/checkout-action
13+
- name: debug
14+
run: git show HEAD && git status -s && git branch

checkout/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Checkout action
2+
3+
Reliably checkout a git repository with submodules.
4+
Uses actions/checkout and supports a subset of its input variables:
5+
`token`, `fetch-depth` and `submodules`. All other inputs are used with the
6+
default values.
7+
8+
This action is intended to be a drop-in replacement for actions/checkout,
9+
improving reliability with submodules and other git repository problems.
10+
11+
Usage:
12+
13+
```diff
14+
- name: Checkout code
15+
- uses: actions/checkout@v3
16+
+ uses: tarantool/actions/checkout@master
17+
# just use the same values for these input variables
18+
with:
19+
fetch-depth: 0
20+
submodules: 'true'
21+
token: ${{ secrets.REPO_ACCESS_TOKEN }}
22+
```
23+
24+
If a workflow had extra tricks against repository problems, they can now be removed:
25+
26+
27+
```diff
28+
- - name: Cleanup workspace
29+
- uses: tarantool/actions/cleanup@master
30+
31+
- name: Checkout code
32+
- uses: actions/checkout@v3
33+
+ uses: tarantool/actions/checkout@master
34+
with:
35+
fetch-depth: 0
36+
submodules: 'true'
37+
token: ${{ secrets.REPO_ACCESS_TOKEN }}
38+
39+
- # Work-around for https://github.com/actions/checkout/issues/435
40+
- - name: Update submodules
41+
- run: |
42+
- pushd tarantool-${{ matrix.tarantool-branch }}
43+
- git submodule update --init --recursive --force
44+
- git fetch origin --prune --progress --recurse-submodules \
45+
- +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
46+
- popd
47+
```

checkout/action.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
name: 'Checkout'
3+
description: >
4+
Reliably checkout a git repository with submodules.
5+
Uses actions/checkout and supports a subset of its input variables:
6+
`token`, `fetch-depth` and `submodules`. All other inputs are used with the
7+
default values.
8+
inputs:
9+
token:
10+
description: >
11+
Personal access token (PAT) used to fetch the repository.
12+
Only required for checking out private repositories.
13+
required: false
14+
default: ${{ github.token }}
15+
fetch-depth:
16+
description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.'
17+
default: 1
18+
submodules:
19+
description: >
20+
Whether to checkout submodules: `true` to checkout submodules, `recursive`
21+
to recursively checkout submodules, or `false` (default) to only checkout
22+
the main repository.
23+
default: false
24+
25+
runs:
26+
using: 'composite'
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v3
30+
id: checkout
31+
continue-on-error: true
32+
with:
33+
token: ${{ inputs.token }}
34+
fetch-depth: ${{ inputs.fetch-depth }}
35+
submodules: ${{ inputs.submodules }}
36+
37+
- name: Cleanup workspace
38+
if: steps.checkout.outcome != 'success'
39+
uses: ./cleanup
40+
41+
- name: Checkout after cleanup
42+
uses: actions/checkout@v3
43+
if: steps.checkout.outcome != 'success'
44+
with:
45+
token: ${{ inputs.token }}
46+
fetch-depth: ${{ inputs.fetch-depth }}
47+
submodules: ${{ inputs.submodules }}
48+
49+
# Work-around for https://github.com/actions/checkout/issues/435
50+
- name: Update submodules including tags
51+
if: inputs.submodules == 'true'
52+
run: |
53+
pushd tarantool-${{ matrix.tarantool-branch }}
54+
git fetch origin --prune --progress \
55+
+refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
56+
popd
57+
shell: bash
58+
59+
- name: Recursively update submodules including tags
60+
if: inputs.submodules == 'recursive'
61+
run: |
62+
pushd tarantool-${{ matrix.tarantool-branch }}
63+
git submodule update --init --recursive --force
64+
git fetch origin --prune --progress --recurse-submodules \
65+
+refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
66+
popd
67+
shell: bash

0 commit comments

Comments
 (0)