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 hype action to workflow #21

Merged
merged 2 commits into from
Feb 9, 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
31 changes: 31 additions & 0 deletions .github/workflows/hype.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Generate README with Hype
on: [pull_request]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22.x"
cache-dependency-path: subdir/go.sum

- name: Install hype
run: go install github.com/gopherguides/hype/cmd/hype@latest

- name: Run hype
run: pushd .hype;hype export -format=markdown -f module.md > ../README.md;popd

- name: Commit README back to the repo
run: |-
git rev-parse --abbrev-ref HEAD
git config user.name 'GitHub Actions'
git config user.email '[email protected]'
git diff --quiet || (git add README.md && git commit -am "Updated README")
git push origin ${{github.event.pull_request.head.ref}}
31 changes: 31 additions & 0 deletions .hype/actions/hype.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Generate README with Hype
on: [pull_request]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22.x"
cache-dependency-path: subdir/go.sum

- name: Install hype
run: go install github.com/gopherguides/hype/cmd/hype@latest

- name: Run hype
run: pushd .hype;hype export -format=markdown -f module.md > ../README.md;popd

- name: Commit README back to the repo
run: |-
git rev-parse --abbrev-ref HEAD
git config user.name 'GitHub Actions'
git config user.email '[email protected]'
git diff --quiet || (git add README.md && git commit -am "Updated README")
git push origin ${{github.event.pull_request.head.ref}}
28 changes: 28 additions & 0 deletions .hype/actions/module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Using Github Actions to update your README

This repo uses the action to keep the README up to date.

## Requirements

For this action to work, you need to either configure your repo with specific permissions, or use a `personal access token`.

### Repo Permissions

You need to give permission to your GitHub Actions to create a pull request in your GitHub repo settings *(Settings -> Actions -> General)*.

Under `Workflow Permissions`

- Check `Allow GitHub Actions to create and approve pull requests`.
- Check `Read and write permissions`

### Personal Access Token

Alternately, you can use tokens to give permission to your action.

It is recommend to use a GitHub [Personnal Acces Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#creating-a-fine-grained-personal-access-token) like: `${{ `{{secrets.PAT}}` }}` instead of using `{{ `${{secrets.GITHUB_TOKEN}}` }}` in GitHub Actions.

## The Action

The current action is set to only generate the readme on a pull request and commit it back to that same pull request. You can modify this to your own needs.

<code src="hype.yml"></code>
5 changes: 5 additions & 0 deletions .hype/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ From the `.hype` directory, run:
hype export -format=markdown -f module.md > ../README.md
```

You can also use a [github action](#using-github-actions-to-update-your-readme) to automatically update your README as well.


<include src="quickstart/module.md"></include>

# README Source
Expand All @@ -23,6 +26,8 @@ Here is the current structure that we are using to create this readme:

<cmd exec="tree" src=".">

<include src="actions/module.md"></include>


# Issues

Expand Down
79 changes: 78 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ From the `.hype` directory, run:
`hype export -format=markdown -f module.md > ../README.md
`

You can also use a [github action](#using-github-actions-to-update-your-readme) to automatically update your README as well.

---

# Quick Start Guide
Expand Down Expand Up @@ -343,6 +345,9 @@ Here is the current structure that we are using to create this readme:
$ tree

.
├── actions
│   ├── hype.yml
│   └── module.md
├── badges.md
├── license.md
├── module.md
Expand All @@ -355,8 +360,80 @@ $ tree
└── hello
└── main.go

4 directories, 7 files
5 directories, 9 files
```
---

# Using Github Actions to update your README

This repo uses the action to keep the README up to date.

## Requirements

For this action to work, you need to either configure your repo with specific permissions, or use a `personal access token`.

### Repo Permissions

You need to give permission to your GitHub Actions to create a pull request in your GitHub repo settings _(Settings -> Actions -> General)_.

Under `Workflow Permissions`


* Check `Allow GitHub Actions to create and approve pull requests`.
* Check `Read and write permissions`


### Personal Access Token

Alternately, you can use tokens to give permission to your action.

It is recommend to use a GitHub [Personnal Acces Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#creating-a-fine-grained-personal-access-token) like: `${{secrets.PAT}}` instead of using `${{secrets.GITHUB_TOKEN}}` in GitHub Actions.

## The Action

The current action is set to only generate the readme on a pull request and commit it back to that same pull request. You can modify this to your own needs.

```yml
name: Generate README with Hype
on: [pull_request]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22.x"
cache-dependency-path: subdir/go.sum

- name: Install hype
run: go install github.com/gopherguides/hype/cmd/hype@latest

- name: Run hype
run: pushd .hype;hype export -format=markdown -f module.md > ../README.md;popd

- name: Commit README back to the repo
run: |-
git rev-parse --abbrev-ref HEAD
git config user.name 'GitHub Actions'
git config user.email '[email protected]'
git diff --quiet || (git add README.md && git commit -am "Updated README")
git push origin ${{github.event.pull_request.head.ref}}

```

---

# Issues

There are several issues that still need to be worked on. Please see the issues tab if you are interested in helping.

---

# License
Expand Down