diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml new file mode 100644 index 0000000..b21fddb --- /dev/null +++ b/.github/workflows/nightly.yaml @@ -0,0 +1,29 @@ +name: Nightly check for sustainability + +on: + schedule: + - cron: "0 10 * * *" # 5 AM EST (GitHub Actions uses UTC) + workflow_dispatch: + +jobs: + run-nightly-script: + name: Run nightly sustainability check + runs-on: ubuntu-latest + + steps: + - name: Checkout default branch + uses: actions/checkout@v4 + with: + fetch-depth: 0 # optional: fetch full history if needed + + - name: Install GH extension + run: gh extension install kassett/gh-commit + shell: bash + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Run nightly script + shell: bash + run: ./integrationTests/general.sh + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/cmd/execute.go b/cmd/execute.go index e9d2e53..43f8aa2 100644 --- a/cmd/execute.go +++ b/cmd/execute.go @@ -11,7 +11,7 @@ import ( ) // VERSION number: changed in CI -const VERSION = "v0.2.0" +const VERSION = "v0.2.1" var rootPath string var repo repository.Repository diff --git a/integrationTests/general.sh b/integrationTests/general.sh new file mode 100755 index 0000000..334ab10 --- /dev/null +++ b/integrationTests/general.sh @@ -0,0 +1,109 @@ +#!/bin/bash + +current_branch=$(git rev-parse --abbrev-ref HEAD) + +for i in {1..2}; do + mkdir tmp > /dev/null 2>&1 + echo "RANDOM1" > tmp/random1.txt + echo "RANDOM2" > tmp/random2.txt + + branch=$(echo random-nightly-branch-$(date +%F)-$((RANDOM % 100 + 1))) + + if [[ $i -eq 1 ]]; then + gh commit tmp/random1.txt tmp/random2.txt \ + -m "Randomly commit for nightly test." \ + -B $branch + else + gh commit -U -A \ + -m "Randomly commit for nightly test." \ + -B $branch + fi + + git fetch + git checkout $branch + + cat tmp/random1.txt + cat tmp/random2.txt + + rm -rf tmp + + git switch - + sleep 1 + + repo_info=$(gh repo view --json owner,name -q '.owner.login + "/" + .name') + gh api -X DELETE repos/$repo_info/git/refs/heads/$branch + git checkout $current_branch +done + +for i in {1..2}; do + mkdir tmp > /dev/null 2>&1 + echo "RANDOM1" > tmp/random1.txt + echo "RANDOM2" > tmp/random2.txt + + branch=$(echo random-nightly-branch-$(date +%F)-$((RANDOM % 100 + 1))) + + if [[ $i -eq 1 ]]; then + gh commit tmp/random1.txt tmp/random2.txt \ + -m "Randomly commit for nightly test." \ + -B $branch + else + gh commit -U -A \ + -m "Randomly commit for nightly test." \ + -B $branch + fi + + git fetch + git checkout $branch + + cat tmp/random1.txt + cat tmp/random2.txt + + rm -rf tmp + + git switch - + sleep 1 + + repo_info=$(gh repo view --json owner,name -q '.owner.login + "/" + .name') + gh api -X DELETE repos/$repo_info/git/refs/heads/$branch + git checkout $current_branch +done + + +for i in {1..2}; do + mkdir tmp > /dev/null 2>&1 + echo "RANDOM1" > tmp/random1.txt + echo "RANDOM2" > tmp/random2.txt + + branch=$(echo random-nightly-branch-$(date +%F)-$((RANDOM % 100 + 1))) + headRef=$(echo random-nightly-branch-$(date +%F)-$((RANDOM % 1000 + 1))) + + if [[ $i -eq 1 ]]; then + gh commit tmp/random1.txt tmp/random2.txt -P \ + -m "Randomly commit for nightly test." \ + -B $branch -H $headRef -T "Title of PR" + else + gh commit -U -A \ + -m "Randomly commit for nightly test." -P \ + -B $branch -H $headRef -T "Title of PR" + fi + + git fetch + git checkout $branch + + cat tmp/random1.txt + cat tmp/random2.txt + + rm -rf tmp + + git switch - + sleep 1 + + pr_number=$(gh pr list --head "$headRef" --json number -q '.[0].number') + echo $pr_number + + repo_info=$(gh repo view --json owner,name -q '.owner.login + "/" + .name') + gh pr close $pr_number + gh api -X DELETE repos/$repo_info/git/refs/heads/$branch + gh api -X DELETE repos/$repo_info/git/refs/heads/$headRef + git checkout $current_branch +done \ No newline at end of file