Skip to content

Commit c4376b6

Browse files
authored
Set GitHub Token as the preferred way of giving access to actions.
Fixes #77. Co-authored-by: rht <rhtbot@protonmail.com>
1 parent 86efe95 commit c4376b6

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,22 @@ GitHub action needs the following credentials for running.
3636

3737
Zulip API key is used for fetching the messages of public streams from the Zulip organization. We recommend creating a bot and using it's API key instead of using your own API key. See https://zulip.com/help/add-a-bot-or-integration for more details.
3838

39-
#### GitHub Personal Access Token
39+
#### GitHub Token
4040

41-
The token is used by the GitHub action for pushing to the repo and running GitHub page builds. You can generate the token by going to https://github.com/settings/tokens. Make sure to enable `repo` and `workflow` while generating the token.
41+
The token is used by the GitHub Actions for pushing to the repo and running GitHub page builds.
42+
It is generated automatically by GitHub Actions itself as `secrets.GITHUB_TOKEN` and can be used right away.
4243

4344
### Step 3 - Store credentials as secrets in the repository
4445

4546
Now that we have generated the credentials, we need to store them in the repository as secrets so that action can access them during run time. For that goto `https://github.com/<username>/<repo-name>/settings/secrets`. `<username>` is your GitHub username and `<repo-name>` is the name of the repo you just created.
4647

47-
Now create the following 4 secrets. Use the credentials generated in the above step as the value of each secret.
48+
Now create the following 3 secrets. Use the credentials generated in the above step as the value of each secret.
4849

4950
|Secret name | Value |
5051
|-----------------------------|----------------------------------------------|
5152
|zulip_organization_url | URL of your Zulip organization. |
5253
|zulip_bot_email | The email of the Zulip bot you created |
5354
|zulip_bot_key | API key of the Zulip bot you created |
54-
|gh_personal_access_token | The GitHub personal access token you created |
55-
5655

5756
### Step 4 - Configure the streams you want to index
5857
`zulip-archive` by default don't know which all public streams to be indexed. You can tell `zulip-archive` which all streams to be indexed by creating a file called `streams.yaml` in the newly created repository. You can make a copy of a default file to start with: `cp default_streams.yaml streams.yaml`
@@ -107,7 +106,8 @@ jobs:
107106
zulip_organization_url: ${{ secrets.zulip_organization_url }}
108107
zulip_bot_email: ${{ secrets.zulip_bot_email }}
109108
zulip_bot_key: ${{ secrets.zulip_bot_key }}
110-
github_personal_access_token: ${{ secrets.gh_personal_access_token }}
109+
# Using GitHub Token that is provided automatically by GitHub Actions
110+
github_token: ${{ secrets.GITHUB_TOKEN }}
111111
delete_history: true
112112
```
113113

action.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ inputs:
1212
description: 'API key of the Zulip bot'
1313
required: true
1414
github_personal_access_token:
15-
description: 'GitHub personal access token'
15+
description: 'GitHub personal access token (deprecated)'
16+
required: false
17+
deprecationMessage: 'Please use `github_token` instead'
18+
github_token:
19+
description: 'GitHub Token/GitHub Personal Access Token'
1620
required: true
1721
delete_history:
1822
description: 'If enabled, will delete the archive history while keeping the most recent version'
@@ -30,6 +34,7 @@ runs:
3034
- ${{ inputs.zulip_organization_url }}
3135
- ${{ inputs.zulip_bot_email }}
3236
- ${{ inputs.zulip_bot_key }}
33-
- ${{ inputs.github_personal_access_token }}
37+
- ${{ inputs.github_token }}
3438
- ${{ inputs.delete_history }}
3539
- ${{ inputs.archive_branch }}
40+
- ${{ inputs.github_personal_access_token }}

entrypoint.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@ set -e
44
zulip_organization_url=$1
55
zulip_bot_email=$2
66
zulip_bot_api_key=$3
7-
github_personal_access_token=$4
7+
github_token=$4
88
delete_history=$5
99
archive_branch=$6
10+
github_personal_access_token=$7
11+
12+
github_personal_access_token=${github_personal_access_token:-NOT_SET}
13+
14+
if [ $github_personal_access_token != "NOT_SET" ]; then
15+
echo "'github_personal_access_token' input has been deprecated."
16+
echo "To migrate to the new setup, you have to replace it with"
17+
echo "github_token. For more info, see"
18+
echo 'https://github.com/zulip/zulip-archive#step-5---enable-zulip-archive-action'
19+
exit 1
20+
fi
1021

1122
# This is a temporary workaround.
1223
# See https://github.com/actions/checkout/issues/766
@@ -38,7 +49,7 @@ pip3 install crudini
3849

3950
# Uses GitHub pages API
4051
# https://docs.github.com/en/rest/pages
41-
auth_header="Authorization: Bearer ${github_personal_access_token}"
52+
auth_header="Authorization: Bearer ${github_token}"
4253
accept_header="Accept: application/vnd.github.switcheroo-preview+json"
4354
page_api_url="https://api.github.com/repos/${GITHUB_REPOSITORY}/pages"
4455
# Enable GitHub pages
@@ -106,7 +117,7 @@ git config --global user.name "Archive Bot"
106117
git add -A
107118
git commit -m "Update archive."
108119

109-
git remote add origin2 https://${GITHUB_ACTOR}:${github_personal_access_token}@github.com/${GITHUB_REPOSITORY}
120+
git remote add origin2 https://${GITHUB_ACTOR}:${github_token}@github.com/${GITHUB_REPOSITORY}
110121

111122
git push origin2 HEAD:$archive_branch -f
112123

0 commit comments

Comments
 (0)