Skip to content

Commit eb1605d

Browse files
robertylewistimabbott
authored andcommitted
GitHub action: Add config option to overwrite history.
1 parent 9cdd617 commit eb1605d

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,19 @@ jobs:
106106
zulip_bot_email: ${{ secrets.zulip_bot_email }}
107107
zulip_bot_key: ${{ secrets.zulip_bot_key }}
108108
github_personal_access_token: ${{ secrets.gh_personal_access_token }}
109+
delete_history: true
109110
```
110111

111112
The above file tells GitHub to run the `zulip-archive` action every 20 minutes. You can adjust the `cron` key to modify the schedule as you feel appropriate. If you Zulip organization history is very large (not the case for most users) we recommend to increase the cron period from running every 30 minutes to maybe run every 1 hour (eg `'0 * * * *'`). This is is because the initial archive run that fetches the messages for the first time takes a lot of time and we don't want the second cron job to start before finishing the first run is over. After the initial run is over you can shorten the cron job period if necessary.
112113

114+
If you are running frequent updates with a busy Zulip organization,
115+
the Git repository that you use to run the action will grow very
116+
quickly. We recommend setting the `delete_history` option to
117+
`true`. This will overwrite the git history in the repository (but
118+
keep all the content). If you are using the repository for more than
119+
just the Zulip archive, you may want to set this to `false`, but be
120+
warned that the repository size may explode.
121+
113122
### Step 6 - Verify everything works
114123

115124
Final step is to verify that everything is working as it is supposed to be. You would have to wait for some time since the action is scheduled to run every 20 minutes (or the time you have configured it to be in above step.) You can track the status of the action by visiting `https://github.com/<github-username>/<repo-name>/actions`. Once the action completes running, you would be able to visit the archive by opening the link mentioned in the action run log at the end. The link would be usually be of the form `<github-username>.github.io/<repo-name>` or `<your-personal-domain>/<repo-name>` if you have configured your own personal domain to point to GitHub pages.

action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ runs:
2222
- ${{ inputs.zulip_bot_email }}
2323
- ${{ inputs.zulip_bot_key }}
2424
- ${{ inputs.github_personal_access_token }}
25+
- ${{ inputs.delete_history }}

entrypoint.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ zulip_organization_url=$1
55
zulip_bot_email=$2
66
zulip_bot_api_key=$3
77
github_personal_access_token=$4
8+
delete_history=$5
89

910
checked_out_repo_path="$(pwd)"
1011
html_dir_path=$checked_out_repo_path
1112
json_dir_path="${checked_out_repo_path}/zulip_json"
1213
_layouts_path="${checked_out_repo_path}/_layouts"
1314
img_dir_path="${checked_out_repo_path}/assets/img"
1415
streams_config_file_path="${checked_out_repo_path}/streams.yaml"
16+
initial_sha="$(git rev-parse HEAD)"
1517

1618
if [ ! -f $streams_config_file_path ]; then
1719
echo "Missing streams.yaml file."
@@ -75,14 +77,35 @@ cd ${checked_out_repo_path}
7577

7678
git checkout master
7779

80+
git fetch origin
81+
82+
current_sha="$(git rev-parse origin/master)"
83+
84+
if [[ "$current_sha" != "$initial_sha" ]]
85+
then
86+
echo "Archive update failed, commits have been added while processing"
87+
exit 1
88+
fi
89+
90+
echo "delete history: $delete_history"
91+
92+
if [[ "$delete_history" == "true" ]]
93+
then
94+
echo "resetting"
95+
rm -rf .git
96+
git init
97+
fi
98+
7899
git config --global user.email "zulip-archive-bot@users.noreply.github.com"
79100
git config --global user.name "Archive Bot"
80101

81102
git add -A
82103
git commit -m "Update archive."
83104

84-
git remote set-url --push origin https://${GITHUB_ACTOR}:${github_personal_access_token}@github.com/${GITHUB_REPOSITORY}
105+
git remote add origin2 https://${GITHUB_ACTOR}:${github_personal_access_token}@github.com/${GITHUB_REPOSITORY}
106+
107+
git push origin2 master -f
85108

86-
git push origin master --force
109+
echo "pushed"
87110

88111
echo "Zulip Archive published/updated in ${github_pages_url}"

0 commit comments

Comments
 (0)