From dc261c7cca5bb9a8cdc056681f87a33cd87a496c Mon Sep 17 00:00:00 2001 From: marshall_lee Date: Tue, 24 Dec 2024 15:07:11 +0800 Subject: [PATCH 1/3] elapsed time action --- .github/actions/basics/action.yml | 48 +++++++++++++++++------ .github/actions/elapsed-time/action.yml | 51 +++++++++++++++++++++++++ .github/workflows/ci.yml | 4 -- .github/workflows/pr.yml | 4 -- 4 files changed, 87 insertions(+), 20 deletions(-) create mode 100644 .github/actions/elapsed-time/action.yml diff --git a/.github/actions/basics/action.yml b/.github/actions/basics/action.yml index 0a1a0ef..d863d92 100644 --- a/.github/actions/basics/action.yml +++ b/.github/actions/basics/action.yml @@ -5,12 +5,26 @@ runs: steps: - uses: actions/checkout@v4 + - uses: ./.github/actions/elapsed-time + with: + statement: "actions/checkout" + - name: Install Rust nightly uses: dtolnay/rust-toolchain@stable with: toolchain: ${{ inputs.rust_nightly }} components: clippy, rustfmt + - uses: ./.github/actions/elapsed-time + with: + statement: "rust-toolchain" + + - uses: Swatinem/rust-cache@v2 + + - uses: ./.github/actions/elapsed-time + with: + statement: "rust-cache" + - name: Install cargo-deny uses: ./.github/actions/install-from-tarball with: @@ -18,6 +32,10 @@ runs: executable: "cargo-deny" target_path: "$CARGO_HOME/bin" + - uses: ./.github/actions/elapsed-time + with: + statement: "Install cargo-deny" + - name: Install lychee uses: ./.github/actions/install-from-tarball with: @@ -25,7 +43,9 @@ runs: executable: "lychee" target_path: "$CARGO_HOME/bin" - - uses: Swatinem/rust-cache@v2 + - uses: ./.github/actions/elapsed-time + with: + statement: "Install lychee" - name: Set up Node.js uses: actions/setup-node@v4 @@ -36,28 +56,32 @@ runs: run: npm install -g markdownlint-cli shell: bash + - uses: ./.github/actions/elapsed-time + with: + statement: "setup-node-cache-action" + - name: Restore lychee cache - id: restore-cache - uses: actions/cache/restore@v4 + uses: actions/cache@v4 with: path: .lycheecache key: cache-lychee-${{ github.sha }} restore-keys: cache-lychee- + - uses: ./.github/actions/elapsed-time + with: + statement: "Restore lychee cache" + - name: Run pre-commit run: | - python3 -m venv venv - source venv/bin/activate - pip install pre-commit - pre-commit run --all-files + time python3 -m venv venv + time source venv/bin/activate + time pip -q install pre-commit + time pre-commit run --all-files shell: bash - - name: Save lychee cache - uses: actions/cache/save@v4 - if: always() + - uses: ./.github/actions/elapsed-time with: - path: .lycheecache - key: ${{ steps.restore-cache.outputs.cache-primary-key }} + statement: "pre-commit" inputs: rust_nightly: diff --git a/.github/actions/elapsed-time/action.yml b/.github/actions/elapsed-time/action.yml new file mode 100644 index 0000000..9b63626 --- /dev/null +++ b/.github/actions/elapsed-time/action.yml @@ -0,0 +1,51 @@ +name: "Elapsed Time" +description: "Print how many seconds have elapsed since the last call" + +inputs: + statement: + description: "Statement to print" + required: true + + reference: + description: "Optional unique name for the timestamp file" + required: false + default: "generic" + +outputs: + delta: + description: "Time delta in seconds since last call" + +runs: + using: "composite" + steps: + - name: Elapsed Time + id: elapsed + shell: bash + run: | + FILE=".elapsed_time_${{ inputs.reference }}" + + # 1) Read previous timestamp if present + if [ -f "$FILE" ]; then + last_time="$(cat "$FILE")" + else + last_time="" + fi + + # 2) Get current time + current_time=$(date +%s) + + # 3) Calculate the delta + if [ -z "$last_time" ]; then + delta=0 + else + delta=$(( current_time - last_time )) + fi + + # 4) Print message + echo "Elapsed time for ${{ inputs.statement }}: $delta seconds" + + # 5) Expose as output (optional) + echo "delta=$delta" >> "$GITHUB_OUTPUT" + + # 6) Write new timestamp + echo "$current_time" > "$FILE" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f01bd4a..444ca2b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -286,12 +286,8 @@ jobs: # Basic actions that must pass before we kick off more expensive tests. basics: runs-on: ubuntu-latest - permissions: - contents: read - pull-requests: write steps: - uses: actions/checkout@v4 - uses: ./.github/actions/basics with: - github_token: ${{ secrets.GITHUB_TOKEN }} rust_nightly: ${{ env.rust_nightly }} diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index e6ee72a..5a11ce7 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -17,12 +17,8 @@ env: jobs: basics: runs-on: ubuntu-latest - permissions: - contents: read - pull-requests: write steps: - uses: actions/checkout@v4 - uses: ./.github/actions/basics with: - github_token: ${{ secrets.GITHUB_TOKEN }} rust_nightly: ${{ env.rust_nightly }} From 9bf0432cac56164467dd602af280e8d83da79480 Mon Sep 17 00:00:00 2001 From: marshall_lee Date: Tue, 24 Dec 2024 16:13:03 +0800 Subject: [PATCH 2/3] markdownlint with pre-commit repo --- .github/actions/basics/action.yml | 13 ------------- .pre-commit-config.yaml | 14 +++++--------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/.github/actions/basics/action.yml b/.github/actions/basics/action.yml index d863d92..7be6069 100644 --- a/.github/actions/basics/action.yml +++ b/.github/actions/basics/action.yml @@ -47,19 +47,6 @@ runs: with: statement: "Install lychee" - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: "latest" - - - name: Install markdownlint-cli - run: npm install -g markdownlint-cli - shell: bash - - - uses: ./.github/actions/elapsed-time - with: - statement: "setup-node-cache-action" - - name: Restore lychee cache uses: actions/cache@v4 with: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 650242b..5c91a30 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,18 +36,14 @@ repos: args: ["deny", "check"] pass_filenames: false - # Markdown linting - - id: markdownlint - name: Markdownlint - language: node - entry: markdownlint - args: ["--ignore", "node_modules"] - pass_filenames: true - files: \.md$ - # Link validation - id: lychee name: Lychee language: system entry: lychee args: ["--no-progress", "--cache"] + + - repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.43.0 + hooks: + - id: markdownlint From 7c8969678e1d81e5cec749c563466418edcfa89e Mon Sep 17 00:00:00 2001 From: marshall_lee Date: Tue, 24 Dec 2024 17:59:25 +0800 Subject: [PATCH 3/3] comments out lychee pre-commit hook --- .pre-commit-config.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5c91a30..d94d683 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,6 +43,13 @@ repos: entry: lychee args: ["--no-progress", "--cache"] + # [WON'T WORK !!!] + # - repo: https://github.com/lycheeverse/lychee.git + # rev: v0.15.1 + # hooks: + # - id: lychee + # args: ["--no-progress", "--cache"] + - repo: https://github.com/igorshubovych/markdownlint-cli rev: v0.43.0 hooks: