How to get the parent commit of a build?



I’m thinking about how I could use the benchcmp tool to run benchmarks as part of my builds, and track how the results change. My idea is to run the benchmarks on the current commit, and then git checkout $CIRCLE_SHA1^ and run the benchmarks again.

However, what about builds with more than one commit? As I understand it, $CIRCLE_SHA1 will give me the last commit in the build, but I really want to compare agains the parent of the first commit.

Parsing out $CIRCLE_COMPARE_URL could maybe work, but I’m hoping there is a cleaner way.

I don’t even want to think about how to handle merge commits, where there are multiple parents. Maybe compare against each of them?


I ended up just parsing out the revision from $CIRCLE_COMPARE_URL. My benchmark workflow now looks like this, in case anyone else finds it helpful:

    working_directory: /go/src/
      - image: our-custom-go-build-image
      - checkout

      - run:
          name: Install benchmark comparison tools
          command: |
            go get
            go get

      - run:
          name: Run benchmarks on this version
          command: go test -benchmem -run=^NONE ./... -bench ^.* | tee benchmark-results-new.txt
      - store_artifacts:
          path: benchmark-results-new.txt

      - run:
          name: Run benchmarks on prior version
          command: |
            git checkout $(echo $CIRCLE_COMPARE_URL | sed -n 's|.*compare/\([^.]*\)\..*$|\1|p')
            go test -benchmem -run=^NONE ./... -bench ^.* | tee benchmark-results-old.txt
      - store_artifacts:
          path: benchmark-results-old.txt

      - run:
          name: Compare benchmarks
          command: benchcmp benchmark-results-old.txt benchmark-results-new.txt | tee benchmark-comparison.txt
      - store_artifacts:
          path: benchmark-comparison.txt
      - run:
          name: Generate comparison SVG
          command: cat benchmark-comparison.txt | benchviz > benchmark-comparison.svg
      - store_artifacts:
          path: benchmark-comparison.svg

It records the benchmark results for this build version, and the prior version (prior to all commits in this build), and also records the benchcmp comparison, and an SVG representation of that comparison, all in the artifacts of the build.


This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.