From 28bf426673a8593f8ca9dd762a7f13b463579fca Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 7 Jan 2024 18:12:48 +0900 Subject: [PATCH] wip --- .github/workflows/ci.yml | 120 +++++++++++++++++++++++---------------- checkout/README.md | 13 +++++ checkout/action.yml | 11 ++++ checkout/main.sh | 37 ++++++++++++ 4 files changed, 131 insertions(+), 50 deletions(-) create mode 100644 checkout/README.md create mode 100644 checkout/action.yml create mode 100755 checkout/main.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d363e9..0cbdb5c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ on: push: branches: - main - - dev + - checkout schedule: - cron: '0 0 * * *' workflow_dispatch: @@ -22,57 +22,77 @@ concurrency: cancel-in-progress: true jobs: - tidy: - uses: taiki-e/github-actions/.github/workflows/tidy.yml@main + # tidy: + # uses: taiki-e/github-actions/.github/workflows/tidy.yml@main - free-device-space: - strategy: - fail-fast: false - matrix: - os: - # https://github.com/actions/runner-images#available-images - - ubuntu-20.04 - - ubuntu-22.04 - - macos-11 - - macos-12 - - macos-13 - - windows-2019 - - windows-2022 - runs-on: ${{ matrix.os }} + actions-checkout: + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - name: Run du -h - run: | - set -eEuxo pipefail - sudo du / -h -d1 2>/dev/null || true - sudo du /home -h -d2 || true - sudo du /opt -h -d2 || true - sudo du /usr -h -d2 || true - sudo du /usr/local/lib -h -d1 || true - sudo du /usr/local/share -h -d1 || true - sudo du /var -h -d1 || true - sudo du /var/lib -h -d1 || true - if: startsWith(matrix.os, 'ubuntu') - - uses: ./free-device-space - - name: Run du -h - run: | - set -eEuxo pipefail - sudo du / -h -d1 2>/dev/null || true - sudo du /home -h -d2 || true - sudo du /opt -h -d2 || true - sudo du /usr -h -d2 || true - sudo du /usr/local/lib -h -d1 || true - sudo du /usr/local/share -h -d1 || true - sudo du /var -h -d1 || true - sudo du /var/lib -h -d1 || true - if: startsWith(matrix.os, 'ubuntu') + - uses: taiki-e/github-actions/checkout@checkout + - uses: taiki-e/install-action@shellcheck + - uses: taiki-e/install-action@shfmt + - run: pip3 install yq + - run: git ls-files + - run: ./tools/tidy.sh - setup-docker: + checkout: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - uses: ./setup-docker + - uses: taiki-e/github-actions/checkout@checkout + - 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 + # matrix: + # os: + # # https://github.com/actions/runner-images#available-images + # - ubuntu-20.04 + # - ubuntu-22.04 + # - macos-11 + # - macos-12 + # - macos-13 + # - windows-2019 + # - windows-2022 + # runs-on: ${{ matrix.os }} + # steps: + # - uses: actions/checkout@v4 + # with: + # persist-credentials: false + # - name: Run du -h + # run: | + # set -eEuxo pipefail + # sudo du / -h -d1 2>/dev/null || true + # sudo du /home -h -d2 || true + # sudo du /opt -h -d2 || true + # sudo du /usr -h -d2 || true + # sudo du /usr/local/lib -h -d1 || true + # sudo du /usr/local/share -h -d1 || true + # sudo du /var -h -d1 || true + # sudo du /var/lib -h -d1 || true + # if: startsWith(matrix.os, 'ubuntu') + # - uses: ./free-device-space + # - name: Run du -h + # run: | + # set -eEuxo pipefail + # sudo du / -h -d1 2>/dev/null || true + # sudo du /home -h -d2 || true + # sudo du /opt -h -d2 || true + # sudo du /usr -h -d2 || true + # sudo du /usr/local/lib -h -d1 || true + # sudo du /usr/local/share -h -d1 || true + # sudo du /var -h -d1 || true + # sudo du /var/lib -h -d1 || true + # if: startsWith(matrix.os, 'ubuntu') + + # setup-docker: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v4 + # with: + # persist-credentials: false + # - uses: ./setup-docker diff --git a/checkout/README.md b/checkout/README.md new file mode 100644 index 0000000..ffd9a7b --- /dev/null +++ b/checkout/README.md @@ -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 +``` diff --git a/checkout/action.yml b/checkout/action.yml new file mode 100644 index 0000000..c7ad4f5 --- /dev/null +++ b/checkout/action.yml @@ -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 diff --git a/checkout/main.sh b/checkout/main.sh new file mode 100755 index 0000000..362d034 --- /dev/null +++ b/checkout/main.sh @@ -0,0 +1,37 @@ +#!/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 + "$@" +} + +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}" + +wd=$(pwd) +g git config --global --add safe.directory "${wd}"