Skip to content

Commit

Permalink
fix(ci): add cleanup workflow to retain generated-docs-preview for …
Browse files Browse the repository at this point in the history
…only the last 25 PRs (#2758)

## Description

<!-- A summary of what this pull request achieves and a rough list of
changes. -->

## Breaking Changes

<!-- Optional, if there are any breaking changes document them,
including how to migrate older code. -->

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist

- [ ] Self-review.
- [ ] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [ ] Tests if relevant.
- [ ] All breaking changes documented.
  • Loading branch information
Arqu authored Oct 1, 2024
1 parent 80ed895 commit 1ea0d3d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 5 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Run tests using the beta Rust compiler

name: Cleanup

on:
schedule:
# 06:50 UTC every Monday
- cron: '50 6 * * 1'
workflow_dispatch:

concurrency:
group: beta-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
IROH_FORCE_STAGING_RELAYS: "1"

jobs:
clean_docs_branch:
permissions:
issues: write
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: generated-docs-preview
- name: Clean docs branch
run: |
cd pr/
# keep the last 25 prs
dirs=$(ls -1d [0-9]* | sort -n)
total_dirs=$(echo "$dirs" | wc -l)
dirs_to_remove=$(echo "$dirs" | head -n $(($total_dirs - 25)))
if [ -n "$dirs_to_remove" ]; then
echo "$dirs_to_remove" | xargs rm -rf
fi
git add .
git commit -m "Cleanup old docs"
git push
26 changes: 21 additions & 5 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,33 @@ name: Docs Preview

on:
pull_request:
workflow_dispatch:
inputs:
pr_number:
required: true
type: string

# ensure job runs sequentially so pushing to the preview branch doesn't conflict
concurrency:
group: ci-docs-preview

env:
IROH_FORCE_STAGING_RELAYS: "1"

jobs:
preview_docs:
permissions:
issues: write
contents: write
timeout-minutes: 30
name: Docs preview
if: "github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork"
if: ${{ (github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' ) && !github.event.pull_request.head.repo.fork }}
runs-on: ubuntu-latest
env:
RUSTC_WRAPPER: "sccache"
SCCACHE_GHA_ENABLED: "on"
SCCACHE_CACHE_SIZE: "50G"
PREVIEW_PATH: pr/${{ github.event.pull_request.number }}/docs
PREVIEW_PATH: pr/${{ github.event.pull_request.number || inputs.pr_number }}/docs

steps:
- uses: actions/checkout@v4
Expand All @@ -43,17 +55,21 @@ jobs:
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
issue-number: ${{ github.event.pull_request.number || inputs.pr_number }}
comment-author: 'github-actions[bot]'
body-includes: Documentation for this PR has been generated

- name: Get current timestamp
id: get_timestamp
run: echo "TIMESTAMP=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV

- name: Create or Update Docs Comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
issue-number: ${{ github.event.pull_request.number || inputs.pr_number }}
comment-id: ${{ steps.fc.outputs.comment-id }}
body: |
Documentation for this PR has been generated and is available at: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ env.PREVIEW_PATH }}/iroh/
Last updated: ${{ github.event.pull_request.updated_at }}
Last updated: ${{ env.TIMESTAMP }}
edit-mode: replace

0 comments on commit 1ea0d3d

Please sign in to comment.