Skip to content

Take Screenshot

Take Screenshot #51

name: Take Screenshot
on:
push:
branches:
- main
paths:
- 'src/**'
- 'img/**'
- 'ui/**'
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
DISPLAY: :99
RUST_LOG: debug
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Cache cargo build
uses: actions/cache@v2
with:
path: target
key: ${{ runner.os }}-cargo-build-target-foo-${{ hashFiles('**/Cargo.lock') }}
- name: Build
run: cargo build --release
- name: Hide Dock
run: defaults write com.apple.dock autohide -bool true && killall Dock
- name: Run and take screenshot
run: |
cargo run --release > cargo.log 2>&1 &
sleep 5
cat cargo.log
window_info=$(osascript -e 'tell application "System Events" to tell process "infoskjerm" to get {position, size} of window 1')
x=$(echo $window_info | cut -d, -f1)
y=$(echo $window_info | cut -d, -f2)
w=$(echo $window_info | cut -d, -f3)
h=$(echo $window_info | cut -d, -f4)
rectangle="${x},${y},${w},${h}"
rectangle=$(echo $rectangle | tr -d ' ')
screencapture -R$rectangle screenshot.png
screencapture fullscreen.png
- name: Commit and push screenshot
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add screenshot.png
git commit -m "Add updated screenshot"
git push
- name: Upload screenshots as artifact
uses: actions/upload-artifact@v2
with:
name: screenshot
path: |
screenshot.png
fullscreen.png