-
Notifications
You must be signed in to change notification settings - Fork 1
73 lines (62 loc) · 2.48 KB
/
updateBase.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Daily Update - COMOKIT-HPC Base folder
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
name: Update base code
steps:
### Activity check
### uses GitHub API to check last non-automagic commit in repository
### if it's older than a day, all other steps are skipped
### From https://github.community/t/trigger-workflow-if-there-is-commit-in-last-24-hours/17074/3
- name: Activity check
run: |
:
#=== Check COMOKIT HPC
curl -sL https://api.github.com/repos/COMOKIT/COMOKIT-HPC/commits | jq -r '[.[]][0]' > $HOME/commit.json
date_repo="$(jq -r '.commit.author.date' $HOME/commit.json)"
timestamp=$(date --utc -d "$date_repo" +%s)
rm -f $HOME/commit.json
days=$(( ( $(date --utc +%s) - $timestamp ) / 86400 ))
echo "Last repository activity : $timestamp ~ $days ago"
#=== ! check
alive=0
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "[WARNING] Ignoring activity limits : workflow triggered manually"
alive=1
else
# Check if last commit on HPC is earlier than a day ago
# If yes run Job, if no stop there
if [ $days -lt 1 ]; then
echo Repository active : $days days
alive=1
else
echo "[WARNING] Repository active : $days days (limit 1) - Nothing to update"
fi
fi
if [ $alive -eq 1 ]; then
echo "GHA_REPO_ALIVE=true" >> $GITHUB_ENV
echo "Rebuild continuous releases"
else
echo "GHA_REPO_ALIVE=false" >> $GITHUB_ENV
echo "[WARNING] Repository not updated"
fi
shell: bash
- name: Checkout code
if: env.GHA_REPO_ALIVE == 'true'
uses: actions/checkout@v2
with:
ref: main
fetch-depth: 0
- name: Update subtree and clean it
if: env.GHA_REPO_ALIVE == 'true'
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git stash
git stash clear
git subtree pull --squash --message="[BOT] Update Base folder" --prefix=base https://github.com/COMOKIT/COMOKIT-HPC.git master
git push