-
Notifications
You must be signed in to change notification settings - Fork 0
55 lines (40 loc) · 1.42 KB
/
permtest.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# This is a basic workflow that is manually triggered
name: Manual workflow test
# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on:
workflow_dispatch:
permissions:
actions: write
jobs:
greet:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v2
- name: check perms
run: |
echo ${{ secrets.GITHUB_TOKEN }} |gh auth login --with-token
gh api -i '${{env.GITHUB_REPOSITORY}}'
- name: do it
run: |
# 3600 = 1hr
# 86400 = 1 day
# 864000 = 10 days
export OlderThan=86400
# Using a two-part query so that we can leverage env variables
query1='.workflow_runs[]| select( .status == "waiting") | {id, created_at, run_number,cancel_url}'
query2='select( .created_at|fromdate < now - (env.OlderThan| tonumber)) | [ .cancel_url] |@tsv'
items=$(gh api "repos/{owner}/{repo}/actions/runs" --jq "$query1" |jq -rc "$query2")
echo $items
i=0
for item in $items; do
echo "$i: Cancelling run $item"
#gh run cancel $item
set +e #
gh api -X POST $item
let "i++"
done