Skip to content

Commit

Permalink
Merge pull request #14 from drink7036290/elapsed-time
Browse files Browse the repository at this point in the history
elapsed time action
  • Loading branch information
drink7036290 authored Dec 24, 2024
2 parents 8a6a06b + 7c89696 commit 186a8f6
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 37 deletions.
51 changes: 31 additions & 20 deletions .github/actions/basics/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,70 @@ 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:
url: "https://github.com/EmbarkStudios/cargo-deny/releases/download/0.16.3/cargo-deny-0.16.3-x86_64-unknown-linux-musl.tar.gz"
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:
url: "https://github.com/lycheeverse/lychee/releases/download/lychee-v0.18.0/lychee-x86_64-unknown-linux-musl.tar.gz"
executable: "lychee"
target_path: "$CARGO_HOME/bin"

- uses: Swatinem/rust-cache@v2

- name: Set up Node.js
uses: actions/setup-node@v4
- uses: ./.github/actions/elapsed-time
with:
node-version: "latest"

- name: Install markdownlint-cli
run: npm install -g markdownlint-cli
shell: bash
statement: "Install lychee"

- 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:
Expand Down
51 changes: 51 additions & 0 deletions .github/actions/elapsed-time/action.yml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
4 changes: 0 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
21 changes: 12 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@ 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"]

# [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:
- id: markdownlint

0 comments on commit 186a8f6

Please sign in to comment.