Skip to content

Commit

Permalink
Make a drop-in replacement for actions/checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
NickVolynkin committed Nov 10, 2022
1 parent 1e1d91e commit 58debef
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/test-checkout.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: Test the checkout action

on:
push:
branches:
- '**'
jobs:
test-checkout:
runs-on: ubuntu-latest
steps:
- uses: tarantool/actions/checkout@nickvolynkin/checkout-action
- name: debug
run: git show HEAD && git status -s && git branch
47 changes: 47 additions & 0 deletions checkout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Checkout action

Reliably checkout a git repository with submodules.
Uses actions/checkout and supports a subset of its input variables:
`token`, `fetch-depth` and `submodules`. All other inputs are used with the
default values.

This action is intended to be a drop-in replacement for actions/checkout,
improving reliability with submodules and other git repository problems.

Usage:

```diff
- name: Checkout code
- uses: actions/checkout@v3
+ uses: tarantool/actions/checkout@master
# just use the same values for these input variables
with:
fetch-depth: 0
submodules: 'true'
token: ${{ secrets.REPO_ACCESS_TOKEN }}
```

If a workflow had extra tricks against repository problems, they can now be removed:


```diff
- - name: Cleanup workspace
- uses: tarantool/actions/cleanup@master

- name: Checkout code
- uses: actions/checkout@v3
+ uses: tarantool/actions/checkout@master
with:
fetch-depth: 0
submodules: 'true'
token: ${{ secrets.REPO_ACCESS_TOKEN }}

- # Work-around for https://github.com/actions/checkout/issues/435
- - name: Update submodules
- run: |
- pushd tarantool-${{ matrix.tarantool-branch }}
- git submodule update --init --recursive --force
- git fetch origin --prune --progress --recurse-submodules \
- +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
- popd
```
67 changes: 67 additions & 0 deletions checkout/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
name: 'Checkout'
description: >
Reliably checkout a git repository with submodules.
Uses actions/checkout and supports a subset of its input variables:
`token`, `fetch-depth` and `submodules`. All other inputs are used with the
default values.
inputs:
token:
description: >
Personal access token (PAT) used to fetch the repository.
Only required for checking out private repositories.
required: false
default: ${{ github.token }}
fetch-depth:
description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.'
default: 1
submodules:
description: >
Whether to checkout submodules: `true` to checkout submodules, `recursive`
to recursively checkout submodules, or `false` (default) to only checkout
the main repository.
default: false

runs:
using: 'composite'
steps:
- name: Checkout
uses: actions/checkout@v3
id: checkout
continue-on-error: true
with:
token: ${{ inputs.token }}
fetch-depth: ${{ inputs.fetch-depth }}
submodules: ${{ inputs.submodules }}

- name: Cleanup workspace
if: steps.checkout.outcome != 'success'
uses: ./cleanup

- name: Checkout after cleanup
uses: actions/checkout@v3
if: steps.checkout.outcome != 'success'
with:
token: ${{ inputs.token }}
fetch-depth: ${{ inputs.fetch-depth }}
submodules: ${{ inputs.submodules }}

# Work-around for https://github.com/actions/checkout/issues/435
- name: Update submodules including tags
if: inputs.submodules == 'true'
run: |
pushd tarantool-${{ matrix.tarantool-branch }}
git fetch origin --prune --progress \
+refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
popd
shell: bash

- name: Recursively update submodules including tags
if: inputs.submodules == 'recursive'
run: |
pushd tarantool-${{ matrix.tarantool-branch }}
git submodule update --init --recursive --force
git fetch origin --prune --progress --recurse-submodules \
+refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/*
popd
shell: bash

0 comments on commit 58debef

Please sign in to comment.