Skip to content
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

Merged
merged 7 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/actions/update-on-new-ipfs-tag/Dockerfile

This file was deleted.

55 changes: 0 additions & 55 deletions .github/actions/update-on-new-ipfs-tag/entrypoint.sh

This file was deleted.

7 changes: 7 additions & 0 deletions .github/actions/update-with-latest-versions/Dockerfile
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
@@ -1,4 +1,4 @@
name: 'Update on new go-ipfs tag'
name: 'Update when a new tag or a new release is available'
inputs:
latest_ipfs_tag:
description: "latest go ipfs tag"
Expand Down
82 changes: 82 additions & 0 deletions .github/actions/update-with-latest-versions/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
Copy link
Contributor Author

@laurentsenta laurentsenta Jun 6, 2022

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).



# 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
Copy link
Member

Choose a reason for hiding this comment

The 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}"
16 changes: 9 additions & 7 deletions .github/workflows/update-on-new-ipfs-tag.yml
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:
Expand All @@ -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
Copy link
Contributor Author

@laurentsenta laurentsenta Jun 6, 2022

Choose a reason for hiding this comment

The 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)

Diff: repo-sync/pull-request@65194d8...65785d9

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"

1 change: 1 addition & 0 deletions docs/install/ipfs-updater.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: IPFS updater
description: The IPFS updater is a command-line tool originally used to help users update their IPFS version. Learn how to install, upgrade, and downgrade Go-IPFS using the IPFS updater.
current-ipfs-updater-version: v1.8.0
---

# IPFS updater
Expand Down
9 changes: 5 additions & 4 deletions docs/install/server-infrastructure.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Server infrastructure
description: IPFS Cluster provides data orchestration across a swarm of IPFS daemons by allocating, replicating, and tracking a global pin-set distributed among multiple peers. Learn how to install it here.
current-ipfs-cluster-version: v1.0.1
---

# Server infrastructure
Expand Down Expand Up @@ -37,13 +38,13 @@ If you're having issues here, head over to the [official Docker documentation to
1. Download the latest `ipfs-cluster-ctl` package from [dist.ipfs.io](https://dist.ipfs.io/#ipfs-cluster-ctl):

```shell
wget https://dist.ipfs.io/ipfs-cluster-ctl/v1.0.0-rc4/ipfs-cluster-ctl_v1.0.0-rc4_linux-amd64.tar.gz
wget https://dist.ipfs.io/ipfs-cluster-ctl/v1.0.1/ipfs-cluster-ctl_v1.0.1_linux-amd64.tar.gz
```

1. Unzip the package:

```shell
tar xvzf ipfs-cluster-ctl_v1.0.0-rc4_linux-amd64.tar.gz
tar xvzf ipfs-cluster-ctl_v1.0.1_linux-amd64.tar.gz

> ipfs-cluster-ctl/ipfs-cluster-ctl
> ipfs-cluster-ctl/LICENSE
Expand All @@ -52,10 +53,10 @@ If you're having issues here, head over to the [official Docker documentation to
> ipfs-cluster-ctl/README.md
```

1. Download the [`docker-compose.yml` file](https://raw.githubusercontent.com/ipfs/ipfs-cluster/v1.0.0-rc4/docker-compose.yml) and place it into the `ipfs-cluster-ctl` directory:
1. Download the [`docker-compose.yml` file](https://raw.githubusercontent.com/ipfs/ipfs-cluster/v1.0.1/docker-compose.yml) and place it into the `ipfs-cluster-ctl` directory:

```shell
wget https://raw.githubusercontent.com/ipfs/ipfs-cluster/v1.0.0-rc4/docker-compose.yml
wget https://raw.githubusercontent.com/ipfs/ipfs-cluster/v1.0.1/docker-compose.yml
```

1. Start the cluster using `docker-compose`. You may have to run as root:
Expand Down