diff --git a/.github/actions/latest-ipfs-tag/Dockerfile b/.github/actions/latest-ipfs-tag/Dockerfile new file mode 100644 index 0000000..34e65f5 --- /dev/null +++ b/.github/actions/latest-ipfs-tag/Dockerfile @@ -0,0 +1,3 @@ +FROM golang:1.17 +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/.github/actions/latest-ipfs-tag/action.yml b/.github/actions/latest-ipfs-tag/action.yml new file mode 100644 index 0000000..c16af5f --- /dev/null +++ b/.github/actions/latest-ipfs-tag/action.yml @@ -0,0 +1,7 @@ +name: 'Find latest go-ipfs tag' +outputs: + latest_tag: + description: "latest go-ipfs tag name" +runs: + using: 'docker' + image: 'Dockerfile' diff --git a/.github/actions/latest-ipfs-tag/entrypoint.sh b/.github/actions/latest-ipfs-tag/entrypoint.sh new file mode 100755 index 0000000..b1c3331 --- /dev/null +++ b/.github/actions/latest-ipfs-tag/entrypoint.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env sh +set -eu + +# extract IPFS release +cd /tmp +git clone https://github.com/ipfs/go-ipfs.git +cd go-ipfs +LATEST_IPFS_TAG=`git describe --tags --abbrev=0` +echo "The latest IPFS tag is ${LATEST_IPFS_TAG}" +echo "::set-output name=latest_tag::${LATEST_IPFS_TAG}" diff --git a/.github/actions/update-on-new-ipfs-tag/Dockerfile b/.github/actions/update-on-new-ipfs-tag/Dockerfile new file mode 100644 index 0000000..34e65f5 --- /dev/null +++ b/.github/actions/update-on-new-ipfs-tag/Dockerfile @@ -0,0 +1,3 @@ +FROM golang:1.17 +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/.github/actions/update-on-new-ipfs-tag/action.yml b/.github/actions/update-on-new-ipfs-tag/action.yml new file mode 100644 index 0000000..29486c9 --- /dev/null +++ b/.github/actions/update-on-new-ipfs-tag/action.yml @@ -0,0 +1,11 @@ +name: 'Update on new go-ipfs tag' +inputs: + latest_ipfs_tag: + description: "latest go ipfs tag" + required: true +outputs: + updated_branch: + description: "name of pushed branch with updated doc" +runs: + using: 'docker' + image: 'Dockerfile' diff --git a/.github/actions/update-on-new-ipfs-tag/entrypoint.sh b/.github/actions/update-on-new-ipfs-tag/entrypoint.sh new file mode 100755 index 0000000..2275c4b --- /dev/null +++ b/.github/actions/update-on-new-ipfs-tag/entrypoint.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env sh +set -eu + +# 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 IPFS tag is ${CURRENT_IPFS_TAG}" + +# extract IPFS release +LATEST_IPFS_TAG=$INPUT_LATEST_IPFS_TAG +echo "The latest IPFS tag is ${LATEST_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 + git checkout -b update-ipfs-to-$LATEST_IPFS_TAG + 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 + 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 go-ipfs dependence to tag $LATEST_IPFS_TAG." + git push -u origin update-ipfs-to-$LATEST_IPFS_TAG +fi +echo "::set-output name=updated_branch::update-ipfs-to-$LATEST_IPFS_TAG" diff --git a/.github/workflows/update-on-new-ipfs-tag.yml b/.github/workflows/update-on-new-ipfs-tag.yml new file mode 100644 index 0000000..745009f --- /dev/null +++ b/.github/workflows/update-on-new-ipfs-tag.yml @@ -0,0 +1,27 @@ +name: Update repo on new ipfs-tag release +on: + push: + # workflow_dispatch: + # schedule: + # - cron: '30 5,17 * * *' # run every day at 5:30am and 5:30pm UTC + +jobs: + update: + runs-on: ubuntu-latest + steps: + - name: Checkout http-api-docs + uses: actions/checkout@v2 + - name: Find latest go-ipfs tag + id: latest_ipfs + uses: ./.github/actions/latest-ipfs-tag + - name: Update http-api-docs + id: update + uses: ./.github/actions/update-on-new-ipfs-tag + 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@v2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + source_branch: ${{ steps.update.outputs.updated_branch }} + pr_title: "Bump go-ipfs dependency to ${{ steps.latest_ipfs.outputs.latest_tag }}" \ No newline at end of file