From 69193197700cf3872df3dfdada09bc0b9a6ae541 Mon Sep 17 00:00:00 2001 From: galargh Date: Fri, 11 Aug 2023 21:13:39 +0200 Subject: [PATCH 1/2] feat: automate adding new go-libp2p versions to perf --- .github/workflows/add-new-impl-versions.yml | 64 +++++++++++++++++++++ perf/impl/go-libp2p/v0.28/.gitignore | 1 - perf/impl/go-libp2p/v0.28/Dockerfile | 14 ----- perf/impl/go-libp2p/v0.28/Makefile | 3 +- 4 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/add-new-impl-versions.yml delete mode 100644 perf/impl/go-libp2p/v0.28/Dockerfile diff --git a/.github/workflows/add-new-impl-versions.yml b/.github/workflows/add-new-impl-versions.yml new file mode 100644 index 000000000..be2e63585 --- /dev/null +++ b/.github/workflows/add-new-impl-versions.yml @@ -0,0 +1,64 @@ +name: Add new implementation versions + +on: + push: + +defaults: + run: + shell: bash + +permissions: + contents: write + pull-requests: write + actions: write + +jobs: + go: + runs-on: ubuntu-latest + env: + DIR: perf/impl/go-libp2p + REPO: libp2p/go-libp2p + BRANCH: perf/go-libp2p + steps: + - name: Checkout test-plans + uses: actions/checkout@v3 + - name: Configure git + run: | + git fetch $BRANCH && git checkout $BRANCH && git rebase $GITHUB_REF -X theirs || git checkout -b $BRANCH + git config --global user.email $GITHUB_ACTOR@users.noreply.github.com + git config --global user.name $GITHUB_ACTOR + - id: go + uses: actions/setup-go@v3 + with: + go-version: stable + - name: Get the latest version (local) + id: local + run: ls -d v* | sort -V | tail -n-1 | xargs -I{} echo "version={}" | tee -a $GITHUB_OUTPUT + working-directory: ${{ env.DIR }} + - name: Get the latest version (remote) + id: remote + env: + GITHUB_TOKEN: ${{ github.token }} + run: gh api repos/$REPO/releases/latest --jq '.tag_name' | xargs -I{} echo "version={}" | tee -a $GITHUB_OUTPUT + - name: Add the latest version + if: ${{ !startsWith(steps.remote.outputs.version, steps.local.outputs.version) }} + env: + LOCAL_VERSION: ${{ steps.local.outputs.version }} + REMOTE_VERSION: ${{ steps.remote.outputs.version }} + GO_VERSION: ${{ steps.go.outputs.go-version }} + GITHUB_TOKEN: ${{ github.token }} + run: | + majorMinorRemoteVersion=$(echo $REMOTE_VERSION | sed 's/\.[0-9]*$//') + majorMinorGoVersion=$(echo $GO_VERSION | sed 's/\.[0-9]*$//') + cp -r $LOCAL_VERSION $majorMinorRemoteVersion + cd $majorMinorRemoteVersion + sed -i "1s/$LOCAL_VERSION/$majorMinorRemoteVersion/g" go.mod + go mod tidy -go=$majorMinorGoVersion + go mod tidy + go get github.com/libp2p/go-libp2p@$REMOTE_VERSION + git add . + git commit -m "chore: add go-libp2p@$REMOTE_VERSION to $DIR" + git push origin $BRANCH --force + gh pr create --title "chore: add go-libp2p@$REMOTE_VERSION to $DIR" --body "This PR adds go-libp2p@$REMOTE_VERSION to $DIR" --head $BRANCH --base $GITHUB_REF + gh workflow run perf.yml --ref $BRANCH + working-directory: ${{ env.DIR }} diff --git a/perf/impl/go-libp2p/v0.28/.gitignore b/perf/impl/go-libp2p/v0.28/.gitignore index 79512b46d..10cdd063f 100644 --- a/perf/impl/go-libp2p/v0.28/.gitignore +++ b/perf/impl/go-libp2p/v0.28/.gitignore @@ -1,3 +1,2 @@ perf .cache -v0.28 diff --git a/perf/impl/go-libp2p/v0.28/Dockerfile b/perf/impl/go-libp2p/v0.28/Dockerfile deleted file mode 100644 index 5bb5b5aae..000000000 --- a/perf/impl/go-libp2p/v0.28/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -# Build Go Binary -FROM golang:1.20-alpine AS builder - -WORKDIR /app -COPY go.mod go.sum ./ -RUN go mod download -COPY *.go ./ -RUN go build -o perf . - -FROM alpine - -COPY --from=builder /app/perf /app/perf - -ENTRYPOINT [ "/app/perf" ] diff --git a/perf/impl/go-libp2p/v0.28/Makefile b/perf/impl/go-libp2p/v0.28/Makefile index b107948be..0b074b44a 100644 --- a/perf/impl/go-libp2p/v0.28/Makefile +++ b/perf/impl/go-libp2p/v0.28/Makefile @@ -3,11 +3,10 @@ GO_FILES := $(wildcard *.go) all: perf perf: $(GO_FILES) - docker run --rm --user "$(shell id -u):$(shell id -g)" -v "$(shell pwd)":/usr/src/myapp -w /usr/src/myapp -e GOCACHE=/usr/src/myapp/.cache golang:1.20 go build -o perf . + docker run --rm --user "$(shell id -u):$(shell id -g)" -v "$(shell pwd)":/usr/src/myapp -w /usr/src/myapp -e GOCACHE=/usr/src/myapp/.cache golang:$(shell awk '/^go [0-9]+(\.[0-9]+)?$$/ {print $$2}' go.mod) go build -o perf . clean: rm perf rm .cache - rm v0.28 .PHONY: all clean From b57d0aaba5d1d24f857ce91b8bfce5b40bee430f Mon Sep 17 00:00:00 2001 From: Piotr Galar Date: Wed, 16 Aug 2023 11:49:38 +0200 Subject: [PATCH 2/2] fix: put add-new-impl-versions.yml on schedule --- .github/workflows/add-new-impl-versions.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/add-new-impl-versions.yml b/.github/workflows/add-new-impl-versions.yml index be2e63585..1574ce704 100644 --- a/.github/workflows/add-new-impl-versions.yml +++ b/.github/workflows/add-new-impl-versions.yml @@ -1,7 +1,10 @@ name: Add new implementation versions on: - push: + workflow_dispatch: + schedule: + # “At minute 36 past every 24th hour.” - https://crontab.guru/#36_*/24_*_*_* + - cron: '36 */24 * * *' defaults: run: