Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs-pr.yml and docs-pr-close.yml workflows #774

Merged
merged 4 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/docs-pr-close.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Clean up PR documentation

on:
pull_request:
types: [closed]

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Checkout docs-site
uses: actions/checkout@v4
with:
ref: gh-pages

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: pip install -e .[docs]

- name: Set git credentials
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"

- name: Remove PR documentation
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
mike delete pr-$PR_NUMBER --push
79 changes: 79 additions & 0 deletions .github/workflows/docs-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Publish PR documentation

on:
pull_request:
types:
- opened
- synchronize

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: checkout docs-site
uses: actions/checkout@v4
with:
ref: gh-pages

- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
# Looks like it's not working very well for other people:
# https://github.com/actions/setup-python/issues/436
# cache: "pip"
# cache-dependency-path: pyproject.toml

- uses: actions/cache@v3
id: cache
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-docs-pr-v00

- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: pip install -e .[docs]

- name: Set git credentials
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"

- name: Deploy hidden docs for PR
run: |
PR_NUMBER=$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')
mike deploy pr-$PR_NUMBER --prop-set hidden=true --push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Comment PR with docs link
uses: actions/github-script@v7
with:
script: |
const pr_number = context.payload.pull_request.number;
const owner = context.repo.owner;
const repo = context.repo.repo;

// Check if a comment already exists
const comments = await github.rest.issues.listComments({
issue_number: pr_number,
owner: owner,
repo: repo
});

const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Documentation for this PR has been built')
);

if (!botComment) {
// Post new comment only if it doesn't exist
await github.rest.issues.createComment({
issue_number: pr_number,
owner: owner,
repo: repo,
body: `Documentation for this PR has been built. You can view it at: https://distilabel.argilla.io/pr-${pr_number}/`
});
}
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
id: cache
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-docs
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-docs-v00

- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
Expand All @@ -46,9 +46,9 @@ jobs:
- run: mike deploy dev --push
if: github.ref == 'refs/heads/develop'
env:
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: mike deploy ${{ github.ref_name }} latest --update-aliases --push
if: startsWith(github.ref, 'refs/tags/')
env:
GH_ACCESS_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9 changes: 4 additions & 5 deletions docs/scripts/gen_popular_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
REPOSITORY = "argilla-io/distilabel"
DATA_PATH = "sections/community/popular_issues.md"

GITHUB_ACCESS_TOKEN = os.getenv(
"GH_ACCESS_TOKEN"
) # public_repo and read:org scopes are required
# public_repo and read:org scopes are required
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")


def fetch_issues_from_github_repository(
Expand Down Expand Up @@ -119,7 +118,7 @@ def get_org_members(auth_token: Union[str, None] = None) -> List[str]:


with mkdocs_gen_files.open(DATA_PATH, "w") as f:
df = fetch_issues_from_github_repository(REPOSITORY, GITHUB_ACCESS_TOKEN)
df = fetch_issues_from_github_repository(REPOSITORY, GITHUB_TOKEN)

open_issues = df.loc[df["State"] == "open"]
engagement_df = (
Expand All @@ -129,7 +128,7 @@ def get_org_members(auth_token: Union[str, None] = None) -> List[str]:
.reset_index()
)

members = get_org_members(GITHUB_ACCESS_TOKEN)
members = get_org_members(GITHUB_TOKEN)
community_issues = df.loc[~df["Author"].isin(members)]
community_issues_df = (
community_issues[
Expand Down
Loading