diff --git a/.github/workflows/test-checkout.yml b/.github/workflows/test-checkout.yml new file mode 100644 index 0000000..4fcc3af --- /dev/null +++ b/.github/workflows/test-checkout.yml @@ -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 \ No newline at end of file diff --git a/checkout/README.md b/checkout/README.md new file mode 100644 index 0000000..86ae7dd --- /dev/null +++ b/checkout/README.md @@ -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 +``` \ No newline at end of file diff --git a/checkout/action.yml b/checkout/action.yml new file mode 100644 index 0000000..c3b9c11 --- /dev/null +++ b/checkout/action.yml @@ -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