|
| 1 | +# Archive your GitHub data |
| 2 | + |
| 3 | +This action archives GitHub-specific data into your repository. |
| 4 | + |
| 5 | +GitHub has data that is not represented in git — like Issues and PRs. The purpose of this action is to capture that data in a portable, usable fashion. |
| 6 | + |
| 7 | +### How does it work? |
| 8 | + |
| 9 | +This action is triggered whenever GitHub data changes — for example, when issues are created or edited. It **does not** capture data that is already represented in your git repo, like commits. |
| 10 | + |
| 11 | +This action is triggered whenever changes are made to GitHub data. See below for a list of events which trigger this action. |
| 12 | + |
| 13 | +The event payload JSON is written into a SQLite database that is stored on an orphan branch called `github-meta`. Because these commits are made to an orphan branch, they won't get in the way of your day-to-day usage of git. |
| 14 | + |
| 15 | +A clone of the repository will include the `github-meta` branch, making it easy to build tooling that uses that data. |
| 16 | + |
| 17 | +## Setup |
| 18 | + |
| 19 | +Clone your repo, and then create/push the orphan branch: |
| 20 | + |
| 21 | +```bash |
| 22 | +# in your repo: |
| 23 | + |
| 24 | +# create the orphan branch |
| 25 | +$ git checkout --orphan github-meta |
| 26 | + |
| 27 | +# Remove all your repo content from the orphan branch. |
| 28 | +# Don't worry — this only affects the orphan branches. Your content is safe! |
| 29 | +$ git rm -rf . |
| 30 | +$ git commit --allow-empty -m "Creating github-meta branch" |
| 31 | + |
| 32 | +# and push it up to github |
| 33 | +$ git push origin github-meta |
| 34 | +``` |
| 35 | + |
| 36 | +Next, setup the action! Copy the following into `.github/workflows/archive.yaml`: |
| 37 | + |
| 38 | +```yaml |
| 39 | +name: GitHub Archive |
| 40 | + |
| 41 | +on: |
| 42 | + create: |
| 43 | + delete: |
| 44 | + push: |
| 45 | + fork: |
| 46 | + gollum: |
| 47 | + issues: |
| 48 | + issue_comment: |
| 49 | + label: |
| 50 | + milestone: |
| 51 | + page_build: |
| 52 | + project: |
| 53 | + project_card: |
| 54 | + project_column: |
| 55 | + public: |
| 56 | + pull_request: |
| 57 | + pull_request_review: |
| 58 | + pull_request_review_comment: |
| 59 | + registry_package: |
| 60 | + release: |
| 61 | + status: |
| 62 | + watch: |
| 63 | + |
| 64 | +jobs: |
| 65 | + archive: |
| 66 | + runs-on: ubuntu-latest |
| 67 | + steps: |
| 68 | + - name: Check out repo |
| 69 | + uses: actions/checkout@v2 |
| 70 | + with: |
| 71 | + ref: 'github-meta' |
| 72 | + - name: Archive event |
| 73 | + uses: githubocto/github-archive-action@v1 |
| 74 | +``` |
| 75 | + |
| 76 | +This workflow definition is triggered for almost all of the [webhook event types that GitHub supports](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#webhook-events). Notably, `workflow_run` is excluded as it would capture runs of this archiving action. |
| 77 | + |
| 78 | +If you don't care about a given kind of event, you can remove that from the list of triggers in the `on:` block of your workflow file. |
| 79 | + |
| 80 | +## How is the data serialized? |
| 81 | + |
| 82 | +The data is written to a [SQLite](https://www.sqlite.org/) database named `github-archive.sqlite` in the `github-meta` branch. It contains one table, `events`, with the following schema: |
| 83 | + |
| 84 | +```sql |
| 85 | +CREATE TABLE events ( |
| 86 | + id TEXT PRIMARY KEY, |
| 87 | + timestamp TEXT NOT NULL, |
| 88 | + kind TEXT NOT NULL, |
| 89 | + event TEXT NOT NULL |
| 90 | +); |
| 91 | +``` |
| 92 | + |
| 93 | +| Column | Description | |
| 94 | +| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |
| 95 | +| id | A globally-unique ID for the captured event record. | |
| 96 | +| timestamp | An timestamp indicating when the event was captured, in [simplified extended ISO-8601 format](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) | |
| 97 | +| kind | The name of the [webhook event type](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#webhook-events) which triggered the action, like `issues` or `pull_request` | |
| 98 | +| event | The JSON payload data for the event | |
| 99 | + |
| 100 | +See the [webhook events documentation](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#webhook-events) to find links to example payloads for each event. |
| 101 | + |
| 102 | +# License |
| 103 | + |
| 104 | +MIT |
0 commit comments