-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
66 lines (57 loc) · 2.41 KB
/
action.yml
File metadata and controls
66 lines (57 loc) · 2.41 KB
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
name: "Reactivate Repository"
description: "GitHub action to prevent GitHub from suspending cronjob based triggers due to repository inactivity."
branding:
icon: "refresh-cw"
color: "gray-dark"
inputs:
commit_message:
description: "Commit message used while committing to the repository."
default: "github-actions: Reactivate repository"
required: false
committer_username:
description: "Username used while committing to the repository."
default: "GitHub Actions [Bot]"
required: false
committer_email:
description: "Email used while committing to the repository."
default: "github-actions[bot]@users.noreply.github.com"
required: false
days_elapsed:
description: "Time elapsed from the last commit to trigger a new automated commit (in days)"
default: "50"
required: false
github_token:
description: "GitHub access token with `contents: write` permission."
default: ${{ github.token }}
required: false
runs:
using: "composite"
steps:
- name: "Checkout Repository"
uses: "actions/checkout@v3"
- name: "Generate Metadata"
id: "metadata"
shell: "bash"
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
lastCommitDateISO8601=$(gh api repos/${{ github.repository }}/branches/${{ github.event.repository.default_branch }} --jq '.commit.commit.author.date')
lastCommitUnixTimestamp=$(date -d $lastCommitDateISO8601 +%s)
currentUnixTimestamp=$(date +%s)
maximumTimeElapsedSinceLastCommit=$(( ${{ inputs.days_elapsed }} * 60 * 60 * 24 ))
elapsedTimeSinceLastCommit=$(($currentUnixTimestamp-$lastCommitUnixTimestamp))
if (( $elapsedTimeSinceLastCommit > $maximumTimeElapsedSinceLastCommit )); then
repositoryStatus="inactive"
else
repositoryStatus="active"
fi
echo "repositoryStatus=$repositoryStatus" >> "$GITHUB_OUTPUT"
- name: Reactivate Repository
if: ${{ steps.metadata.outputs.repositoryStatus == 'inactive' }}
shell: "bash"
run: |
git config --global user.name "${{ inputs.committer_username }}"
git config --global user.email "${{ inputs.committer_email }}"
git remote set-url origin https://x-access-token:${{ inputs.github_token }}@github.com/$GITHUB_REPOSITORY
git commit --allow-empty -s -m "${{ inputs.commit_message }}"
git push