Skip to content

Commit

Permalink
GitHub action: Add config option to overwrite history.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertylewis authored and timabbott committed Sep 4, 2020
1 parent 9cdd617 commit eb1605d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,19 @@ jobs:
zulip_bot_email: ${{ secrets.zulip_bot_email }}
zulip_bot_key: ${{ secrets.zulip_bot_key }}
github_personal_access_token: ${{ secrets.gh_personal_access_token }}
delete_history: true
```

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.

If you are running frequent updates with a busy Zulip organization,
the Git repository that you use to run the action will grow very
quickly. We recommend setting the `delete_history` option to
`true`. This will overwrite the git history in the repository (but
keep all the content). If you are using the repository for more than
just the Zulip archive, you may want to set this to `false`, but be
warned that the repository size may explode.

### Step 6 - Verify everything works

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.
Expand Down
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ runs:
- ${{ inputs.zulip_bot_email }}
- ${{ inputs.zulip_bot_key }}
- ${{ inputs.github_personal_access_token }}
- ${{ inputs.delete_history }}
27 changes: 25 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ zulip_organization_url=$1
zulip_bot_email=$2
zulip_bot_api_key=$3
github_personal_access_token=$4
delete_history=$5

checked_out_repo_path="$(pwd)"
html_dir_path=$checked_out_repo_path
json_dir_path="${checked_out_repo_path}/zulip_json"
_layouts_path="${checked_out_repo_path}/_layouts"
img_dir_path="${checked_out_repo_path}/assets/img"
streams_config_file_path="${checked_out_repo_path}/streams.yaml"
initial_sha="$(git rev-parse HEAD)"

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

git checkout master

git fetch origin

current_sha="$(git rev-parse origin/master)"

if [[ "$current_sha" != "$initial_sha" ]]
then
echo "Archive update failed, commits have been added while processing"
exit 1
fi

echo "delete history: $delete_history"

if [[ "$delete_history" == "true" ]]
then
echo "resetting"
rm -rf .git
git init
fi

git config --global user.email "[email protected]"
git config --global user.name "Archive Bot"

git add -A
git commit -m "Update archive."

git remote set-url --push origin https://${GITHUB_ACTOR}:${github_personal_access_token}@github.com/${GITHUB_REPOSITORY}
git remote add origin2 https://${GITHUB_ACTOR}:${github_personal_access_token}@github.com/${GITHUB_REPOSITORY}

git push origin2 master -f

git push origin master --force
echo "pushed"

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

0 comments on commit eb1605d

Please sign in to comment.