-
Notifications
You must be signed in to change notification settings - Fork 411
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
auto-update documented version for external projects #1169
Changes from all commits
3dd5ae4
8d882db
b880e72
2b438de
8da7ab8
1956675
efac06e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM golang:1.17 | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
RUN apt update && apt install -y jq && rm -rf /var/lib/apt/lists/* | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
ENTRYPOINT ["/entrypoint.sh"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env bash | ||
set -eu | ||
|
||
BRANCH=bump-documentation-to-latest-versions | ||
LATEST_IPFS_TAG=$INPUT_LATEST_IPFS_TAG | ||
|
||
echo "The latest IPFS tag is ${LATEST_IPFS_TAG}" | ||
|
||
ROOT=`pwd` | ||
git checkout -b ${BRANCH} | ||
API_FILE=`pwd`/docs/reference/http/api.md | ||
|
||
|
||
# Update http api docs and cli docs | ||
|
||
cd tools/http-api-docs | ||
|
||
# extract go-ipfs release tag used in http-api-docs from go.mod in this repo | ||
CURRENT_IPFS_TAG=`grep 'github.com/ipfs/go-ipfs ' ./go.mod | awk '{print $2}'` | ||
echo "The currently used go-ipfs tag in http-api-docs is ${CURRENT_IPFS_TAG}" | ||
|
||
# make the upgrade, if newer go-ipfs tags exist | ||
if [ "$CURRENT_IPFS_TAG" = "$LATEST_IPFS_TAG" ]; then | ||
echo "http-api-docs already uses the latest go-ipfs tag." | ||
else | ||
# update http-api-docs | ||
sed "s/^\s*github.com\/ipfs\/go-ipfs\s\+$CURRENT_IPFS_TAG\s*$/ github.com\/ipfs\/go-ipfs $LATEST_IPFS_TAG/" go.mod > go.mod2 | ||
mv go.mod2 go.mod | ||
go mod tidy | ||
make | ||
http-api-docs > $API_FILE | ||
|
||
# update cli docs | ||
cd $ROOT # go back to root of ipfs-docs repo | ||
git clone https://github.com/ipfs/go-ipfs.git | ||
cd go-ipfs | ||
git fetch --all --tags | ||
git checkout tags/$LATEST_IPFS_TAG | ||
go install ./cmd/ipfs | ||
cd $ROOT/docs/reference | ||
./generate-cli-docs.sh | ||
fi | ||
|
||
|
||
# Update external tools versions | ||
|
||
update_version() { | ||
INPUT_REPOSITORY=$1 | ||
INPUT_VERSION_IDENTIFIER=$2 | ||
|
||
LATEST_VERSION_TAG=`curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${INPUT_REPOSITORY}/releases/latest | jq --raw-output ".tag_name"` | ||
LATEST_VERSION_NUMBER=${LATEST_VERSION_TAG:1} | ||
|
||
echo "Updating documentation files that rely on ${INPUT_VERSION_IDENTIFIER} to ${LATEST_VERSION_TAG}" | ||
|
||
while read -r file; do | ||
echo "updating ${INPUT_REPOSITORY} version to ${LATEST_VERSION_NUMBER} in ${file}" | ||
CURRENT_VERSION_TAG=`awk "/${INPUT_VERSION_IDENTIFIER}/{print \\$2; exit;}" "${file}"` | ||
CURRENT_VERSION_NUMBER=${CURRENT_VERSION_TAG:1} | ||
sed -E -i "s/$CURRENT_VERSION_NUMBER/$LATEST_VERSION_NUMBER/g" ${file} | ||
done <<< "$(grep "${INPUT_VERSION_IDENTIFIER}" ./docs -R --files-with-matches)" | ||
} | ||
|
||
cd "${ROOT}" | ||
update_version ipfs/ipfs-update current-ipfs-updater-version | ||
update_version ipfs/ipfs-cluster current-ipfs-cluster-version | ||
update_version ipfs/go-ipfs current-ipfs-version | ||
Comment on lines
+65
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @johnnymatthews for now we track updates of these three, but if we ever add more projects, we can add them here with ease (as long they are on github and publish releases there) |
||
|
||
|
||
# Push on change | ||
|
||
if [[ ! `git status --porcelain` ]]; then | ||
echo "No changes to commit." | ||
exit 0; | ||
fi | ||
|
||
git config --global user.email "${GITHUB_ACTOR}" | ||
git config --global user.name "${GITHUB_ACTOR}@users.noreply.github.com" | ||
git add -u | ||
git commit -m "Bumped documentation & installation docs." | ||
git push -fu origin ${BRANCH} | ||
echo "::set-output name=updated_branch::${BRANCH}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
name: Update docs on new ipfs-tag release | ||
name: Update docs on new version (ipfs, ipfs-cluster, etc.) | ||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '30 5,17 * * *' # run every day at 5:30am and 5:30pm UTC | ||
workflow_call: | ||
|
||
jobs: | ||
update: | ||
|
@@ -13,18 +14,19 @@ jobs: | |
- name: Find latest go-ipfs tag | ||
id: latest_ipfs | ||
uses: ./.github/actions/latest-ipfs-tag | ||
- name: Update http-api-docs | ||
- name: Update docs | ||
id: update | ||
uses: ./.github/actions/update-on-new-ipfs-tag | ||
uses: ./.github/actions/update-with-latest-versions | ||
with: | ||
latest_ipfs_tag: ${{ steps.latest_ipfs.outputs.latest_tag }} | ||
- name: pull-request # don't create a pr if there was no new ipfs tag | ||
uses: repo-sync/pull-request@65194d8015be7624d231796ddee1cd52a5023cb3 #v2.16 | ||
if: ${{ steps.update.outputs.updated_branch }} | ||
- name: pull-request | ||
uses: repo-sync/pull-request@65785d95a5a466e46a9d0708933a3bd51bbf9dde #v2.6.2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I started seeing a workspace error (https://github.com/laurentsenta/ipfs-docs/runs/6756806053?check_suite_focus=true) in my github action, had to update. I think the previous version was a typo (2.6.1, not 16) |
||
if: ${{ steps.update.outputs.updated_branch }} # don't create a pr if there was no branch pushed | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
source_branch: ${{ steps.update.outputs.updated_branch }} | ||
destination_branch: "main" | ||
pr_title: "Bump references to go-ipfs ${{ steps.latest_ipfs.outputs.latest_tag }}" | ||
pr_title: "Update documentation ${{ steps.latest_ipfs.outputs.latest_tag }}" | ||
pr_body: "Release Notes: https://github.com/ipfs/go-ipfs/releases/${{ steps.latest_ipfs.outputs.latest_tag }}" | ||
pr_label: "needs/triage,P0" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: github doesn't detect the move so it looks like I created the whole file. This PR really "just" move the update version code lower and calls it thrice.
We also push to a unique branch on file changes, instead of something like
new-documentation-${NEW_TAG}
because documentation updates are not only tied to go-ipfs versions anymore.I was thinking about extracting the version replace script to its own action, but I'm under the impression that would make the code more complex (spread it around 3 actions instead of a single script file).