mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-20 12:14:50 +02:00
ci: add cache clearing to PR merges (#874)
* ci: add cache clearing to PR merges * some renaming * small change to force cache * add manual run option
This commit is contained in:
parent
29bc0b67ba
commit
7ae8e66a3a
2
.github/workflows/build_releases.yml
vendored
2
.github/workflows/build_releases.yml
vendored
@ -6,7 +6,7 @@
|
|||||||
# - FreeBSD (x86_64)
|
# - FreeBSD (x86_64)
|
||||||
# - macOS (aarch64)
|
# - macOS (aarch64)
|
||||||
|
|
||||||
name: "Build Releases"
|
name: "build releases"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
26
.github/workflows/clear-pr-cache.yml
vendored
Normal file
26
.github/workflows/clear-pr-cache.yml
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Simple job to clear the cache used by a PR when it is closed/merged.
|
||||||
|
|
||||||
|
name: "clear PR cache"
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
id:
|
||||||
|
description: "Which id to clear:"
|
||||||
|
required: false
|
||||||
|
pull_request:
|
||||||
|
types:
|
||||||
|
- closed
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
clear-cache:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
steps:
|
||||||
|
- run: |
|
||||||
|
if [[ -z "${{ github.event.inputs.id }}" ]]; then
|
||||||
|
python ./scripts/clear_cache.py ${{ github.event.pull_request.number }}
|
||||||
|
else
|
||||||
|
python ./scripts/clear_cache.py ${{ github.event.inputs.id }}
|
||||||
|
fi
|
2
.github/workflows/test-docs.yml
vendored
2
.github/workflows/test-docs.yml
vendored
@ -1,6 +1,6 @@
|
|||||||
# Small CI workflow to test if mkdocs documentation can be successfully built.
|
# Small CI workflow to test if mkdocs documentation can be successfully built.
|
||||||
|
|
||||||
name: test-docs
|
name: test docs
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
pull_request:
|
pull_request:
|
||||||
|
58
scripts/clear_cache.py
Normal file
58
scripts/clear_cache.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#!/bin/python3
|
||||||
|
|
||||||
|
# A simple script to clean caches matching a PR ID.
|
||||||
|
#
|
||||||
|
# Expects a GitHub token in the environment variables as GITHUB_TOKEN.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
from urllib.error import HTTPError, URLError
|
||||||
|
|
||||||
|
from urllib.request import Request, urlopen
|
||||||
|
|
||||||
|
URL = "https://api.github.com/repos/ClementTsang/bottom/actions/caches"
|
||||||
|
|
||||||
|
|
||||||
|
def cache_list_request(key):
|
||||||
|
request = Request(URL, method="GET")
|
||||||
|
request.add_header("Accept", "application/vnd.github+json")
|
||||||
|
request.add_header("Authorization", "Bearer {}".format(key))
|
||||||
|
return request
|
||||||
|
|
||||||
|
|
||||||
|
def delete_cache_request(key, id):
|
||||||
|
request = Request("{}/{}".format(URL, id), method="DELETE")
|
||||||
|
request.add_header("Accept", "application/vnd.github+json")
|
||||||
|
request.add_header("Authorization", "Bearer {}".format(key))
|
||||||
|
return request
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
args = sys.argv
|
||||||
|
env = os.environ
|
||||||
|
|
||||||
|
key = env["GITHUB_TOKEN"]
|
||||||
|
pr_id = args[1]
|
||||||
|
ref = "refs/pull/{}/merge".format(pr_id)
|
||||||
|
|
||||||
|
with urlopen(cache_list_request(key)) as response:
|
||||||
|
response = json.load(response)
|
||||||
|
caches = response["actions_caches"]
|
||||||
|
for cache in caches:
|
||||||
|
if cache["ref"] == ref:
|
||||||
|
id = cache["id"]
|
||||||
|
try:
|
||||||
|
print("Deleting ID {}...".format(id))
|
||||||
|
urlopen(delete_cache_request(key, id))
|
||||||
|
except HTTPError as e:
|
||||||
|
print("HTTPError with delete, error code {}.".format(e.code))
|
||||||
|
except URLError as _:
|
||||||
|
print("URLError with delete.")
|
||||||
|
else:
|
||||||
|
print("Successfully deleted cache ID {}!".format(id))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
@ -347,7 +347,7 @@ pub fn update_data(app: &mut App) {
|
|||||||
{
|
{
|
||||||
let data = &app.converted_data.cpu_data;
|
let data = &app.converted_data.cpu_data;
|
||||||
for cpu in app.cpu_state.widget_states.values_mut() {
|
for cpu in app.cpu_state.widget_states.values_mut() {
|
||||||
cpu.update_table(data)
|
cpu.update_table(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user