use get()
instead of has_key
for better performance
#25
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: vim-startuptime | |
on: [push, pull_request] | |
env: | |
GIST_TOKEN: ${{ secrets.GIST_TOKEN }} | |
jobs: | |
measure-speed: | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Vim | |
id: vim | |
uses: thinca/action-setup-vim@v2 | |
with: | |
vim_version: 'head' | |
vim_type: 'vim' | |
cache: 'false' | |
download: 'never' | |
- name: Show Vim version | |
run: | | |
${{ steps.vim.outputs.executable }} --version | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: 'stable' | |
# disable cache as this repository does not have go.sum. | |
cache: 'false' | |
- name: Setup vim-startuptime | |
run: | | |
go install github.com/rhysd/vim-startuptime@latest | |
- name: Setup .vimrc | |
run: | | |
cp .vimrc ~/.vimrc | |
- name: Install Dependencies | |
run: | | |
git clone --depth 1 https://github.com/satorunooshie/pairscolorscheme.git | |
mkdir -p ~/.vim/colors | |
cp ./pairscolorscheme/colors/pairs.vim ~/.vim/colors/ | |
- name: Run vim-startuptime | |
run: | | |
vim-startuptime -vimpath ${{ steps.vim.outputs.executable }} -count 300 -warmup 50 -script >> output.txt | |
echo total_average_time=$(cat output.txt | grep 'Total Average:' | awk '{printf "%.2f %s", $3, $4}') >> $GITHUB_ENV | |
- name: Update badge | |
run: | | |
json=$(echo "{\"files\":{\"vim-startuptime.json\":{\"content\":\"{\\\"schemaVersion\\\":1,\\\"style\\\":\\\"for-the-badge\\\",\\\"label\\\":\\\"startuptime\\\",\\\"message\\\":\\\"${{ env.total_average_time }}\\\",\\\"logoColor\\\":\\\"#019733\\\",\\\"color\\\":\\\"brightgreen\\\",\\\"namedLogo\\\":\\\"vim\\\"}\"}}}") | |
curl -s -L \ | |
-X PATCH \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer ${GIST_TOKEN}" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
https://api.github.com/gists/23f13f7ddec85107fb2357f08f03ab1e \ | |
-d "$json" | |
- name: Create GitHub Step Summary | |
run: | | |
echo '### Vim Startup Time Result 🚀' >> $GITHUB_STEP_SUMMARY | |
echo "| AVERAGE | MAX | MIN | FILE |" >> $GITHUB_STEP_SUMMARY | |
echo "|-----------|---------|---------|-------------|" >> $GITHUB_STEP_SUMMARY | |
# extract the necessary lines from the output and process them in Markdown format. | |
grep -E '^[[:space:]]*[0-9]' "output.txt" | while read -r line; do | |
echo "$line" | |
average=$(echo "$line" | awk '{print $1}') | |
max=$(echo "$line" | awk '{print $2}') | |
min=$(echo "$line" | awk '{print $3}' | sed 's/:$//') | |
file=$(echo "$line" | awk '{$1=$2=$3=""; print $0}' | sed 's/^ *//') | |
echo "| $average | $max | $min | $file |" >> $GITHUB_STEP_SUMMARY | |
done |