Skip to content

Commit

Permalink
Add checkout action
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jan 7, 2024
1 parent 2b07420 commit df8c7ad
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 27 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/check-external-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: taiki-e/github-actions/checkout@main
- id: pre
run: |
set -eEuo pipefail
Expand Down
30 changes: 24 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ jobs:
tidy:
uses: taiki-e/github-actions/.github/workflows/tidy.yml@main

checkout:
runs-on: ubuntu-latest
steps:
- uses: taiki-e/github-actions/checkout@main
- uses: taiki-e/install-action@shellcheck
- uses: taiki-e/install-action@shfmt
- run: pip3 install yq
- run: git ls-files
- run: ./tools/tidy.sh
# For comparison
# actions-checkout:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# with:
# persist-credentials: false
# - uses: taiki-e/install-action@shellcheck
# - uses: taiki-e/install-action@shfmt
# - run: pip3 install yq
# - run: git ls-files
# - run: ./tools/tidy.sh

free-device-space:
strategy:
fail-fast: false
Expand All @@ -40,9 +62,7 @@ jobs:
- windows-2022
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: taiki-e/github-actions/checkout@main
- name: Run du -h
run: |
set -eEuxo pipefail
Expand Down Expand Up @@ -72,7 +92,5 @@ jobs:
setup-docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: taiki-e/github-actions/checkout@main
- uses: ./setup-docker
4 changes: 1 addition & 3 deletions .github/workflows/deny.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: taiki-e/github-actions/checkout@main
- name: Install Rust
run: rustup toolchain add "${{ inputs.rust }}" --no-self-update --profile minimal && rustup default "${{ inputs.rust }}"
- uses: taiki-e/install-action@cargo-deny
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: taiki-e/github-actions/checkout@main
- name: Install Rust
run: rustup toolchain add "${{ inputs.rust }}" --no-self-update --profile minimal && rustup default "${{ inputs.rust }}"
# Refs:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/msrv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: taiki-e/github-actions/checkout@main
- uses: taiki-e/github-actions/free-device-space@main
- uses: taiki-e/install-action@cargo-hack
- run: |
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/release-dry-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: taiki-e/github-actions/checkout@main
- run: pip3 install yq
# TODO: move this script to its own file to apply shfmt and shellcheck.
- id: parse
Expand Down Expand Up @@ -110,9 +108,7 @@ jobs:
runs-on: ${{ matrix.os || 'ubuntu-20.04' }}
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: taiki-e/github-actions/checkout@main
- name: Install Rust
run: rustup toolchain add "${{ inputs.rust }}" --no-self-update --profile minimal && rustup default "${{ inputs.rust }}"
- uses: taiki-e/setup-cross-toolchain-action@v1
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: taiki-e/github-actions/checkout@main
- id: pre
run: |
if [[ -n "$(git ls-files '*.rs')" ]]; then
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ supposed to only be used in infra managed by us.
- [**deploy-gh-pages**](deploy-gh-pages): Deploy GitHub Pages.
- [**free-device-space**](free-device-space): Free device space.
- [**setup-docker**](setup-docker): Setup docker.
- [**checkout**](checkout): Checking out a repository.

## Reusable workflows

Expand Down
13 changes: 13 additions & 0 deletions checkout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# checkout

GitHub Action for checking out a repository.
There is no stability guarantee for this action, since it's supposed to only be
used in infra managed by us.

## Usage

See [action.yml](action.yml)

```yaml
- uses: taiki-e/github-actions/checkout@main
```
11 changes: 11 additions & 0 deletions checkout/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: checkout
description: GitHub Action for checking out a repository.

# Note:
# - inputs.* should be manually mapped to INPUT_* due to https://github.com/actions/runner/issues/665
# - Use GITHUB_*/RUNNER_* instead of github.*/runner.* due to https://github.com/actions/runner/issues/2185
runs:
using: composite
steps:
- run: bash --noprofile --norc "${GITHUB_ACTION_PATH:?}/main.sh"
shell: bash
38 changes: 38 additions & 0 deletions checkout/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0 OR MIT
set -eEuo pipefail
IFS=$'\n\t'

g() {
local cmd="$1"
shift
IFS=' '
echo "::group::${cmd} $*"
IFS=$'\n\t'
"${cmd}" "$@"
}
retry() {
for i in {1..10}; do
if "$@"; then
return 0
else
sleep "${i}"
fi
done
"$@"
}

wd=$(pwd)

g git version

g git init
g git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"

g git config --local gc.auto 0

g retry git -c protocol.version=2 fetch --no-tags --prune --no-recurse-submodules --depth=1 origin "+${GITHUB_SHA}:${GITHUB_REF}"

g retry git checkout --progress --force "${GITHUB_REF}"

g git config --global --add safe.directory "${wd}"

0 comments on commit df8c7ad

Please sign in to comment.