-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from emteknetnz/main
NEW Create action
- Loading branch information
Showing
4 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: Auto-tag | ||
on: | ||
push: | ||
tags: | ||
- '*.*.*' | ||
jobs: | ||
auto-tag: | ||
name: Auto-tag | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Auto-tag | ||
uses: silverstripe/gha-auto-tag@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__response.json | ||
__response.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,24 @@ | ||
# gha-keepalive | ||
GitHub Action - Periodically re-enable repository cron workflows | ||
# GitHub Actions - Keepalive | ||
|
||
GitHub Action - Periodically re-enable all repository cron workflows that would otherwise auto-disable after 60 days of no repository activity - see [GitHub docs](https://docs.github.com/en/actions/learn-github-actions/usage-limits-billing-and-administration#disabling-and-enabling-workflows). | ||
|
||
## Usage | ||
|
||
There are no inputs for configuring this action - just define your schedule so that it runs every 60 days or less (in the below example it is run on the first of each month). | ||
|
||
**.github/workflows/keepalive.yml** | ||
```yml | ||
name: Keepalive | ||
on: | ||
# Run on a schedule of once per month | ||
schedule: | ||
- cron: '0 0 1 * *' | ||
workflow_dispatch: | ||
jobs: | ||
keepalive: | ||
name: Keepalive | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Keepalive | ||
uses: silverstripe/gha-keepalive@main | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: Keepalive repository cron workflows | ||
description: GitHub Action to re-enable repository cron workflows to prevent them from stopping after 60 days | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
|
||
- name: Keepalive | ||
shell: bash | ||
env: | ||
GITHUB_REPOSITORY: ${{ github.repository }} | ||
run: | | ||
# https://docs.github.com/en/rest/actions/workflows#list-repository-workflows | ||
RESP_CODE=$(curl -w %{http_code} -s -o __response.json \ | ||
-X GET https://api.github.com/repos/$GITHUB_REPOSITORY/actions/workflows \ | ||
-H "Accept: application/vnd.github.v3+json") | ||
if [[ $RESP_CODE != "200" ]]; then | ||
echo "Unable to read repository workflows - HTTP response code was $RESP_CODE" | ||
exit 1 | ||
fi | ||
IDS=$(jq -r .workflows[].id __response.json) | ||
if [[ $IDS == "" ]]; then | ||
echo "This repository has no workflows" | ||
exit 0 | ||
fi | ||
for ID in $IDS; do | ||
PTH=$(jq -r ".workflows[] | select(.id==$ID) | .path" __response.json) | ||
URL=$(jq -r ".workflows[] | select(.id==$ID) | .html_url" __response.json) | ||
URL=${URL//github\.com/raw.githubusercontent.com} | ||
URL=${URL//$GITHUB_REPOSITORY\/blob/$GITHUB_REPOSITORY} | ||
# Fetch raw workflow yml | ||
RESP_CODE=$(curl -w %{http_code} -s -o __response.yml \ | ||
-X GET $URL \ | ||
-H "Accept: application/vnd.github.v3+json") | ||
if [[ $RESP_CODE != "200" ]]; then | ||
echo "Unable to fetch raw content for workflow $PTH with ID $ID from $URL - http response code was $RESP_CODE" | ||
echo "Workflow is probably not on default branch" | ||
echo "If this workflow runs on a cron, it will not keepalive" | ||
else | ||
YML=$(cat __response.yml) | ||
RX="schedule:\s+- cron:" | ||
if ! [[ $YML =~ $RX ]]; then | ||
echo "Workflow $PTH with ID $ID does not run on a cron, no need to re-enable" | ||
else | ||
# https://docs.github.com/en/rest/actions/workflows#enable-a-workflow | ||
RESP_CODE=$(curl -w %{http_code} -s -o /dev/null \ | ||
-X PUT https://api.github.com/repos/$GITHUB_REPOSITORY/actions/workflows/$ID/enable \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
-H "Authorization: token ${{ github.token }}") | ||
if [[ $RESP_CODE != "204" ]]; then | ||
echo "Unable to enable workflow $PTH with ID $ID - HTTP response code was $RESP_CODE" | ||
exit 1 | ||
fi | ||
echo "Re-enabled workflow $PTH with ID $ID" | ||
fi | ||
fi | ||
done |