From 1876f68127328353f1f181eae2f963d69eae68b4 Mon Sep 17 00:00:00 2001 From: Paul Balaji Date: Mon, 24 Jun 2024 11:18:08 +0100 Subject: [PATCH] feat: pin monorepo to a specific registry version (#4031) feat: pin monorepo to a specific registry version - introducing a `.registryrc`, which can be a commit hash, branch or tag - introduce a new action just for checking out a registry - remove registry caching because it's quicker now to just checkout the specified version --------- Signed-off-by: Paul Balaji <10051819+paulbalaji@users.noreply.github.com> --- .github/actions/checkout-registry/action.yml | 28 +++++ .github/workflows/monorepo-docker.yml | 12 ++- .github/workflows/test-skipped.yml | 6 -- .github/workflows/test.yml | 101 +++---------------- .registryrc | 1 + Dockerfile | 9 +- 6 files changed, 57 insertions(+), 100 deletions(-) create mode 100644 .github/actions/checkout-registry/action.yml create mode 100644 .registryrc diff --git a/.github/actions/checkout-registry/action.yml b/.github/actions/checkout-registry/action.yml new file mode 100644 index 000000000..929ea7539 --- /dev/null +++ b/.github/actions/checkout-registry/action.yml @@ -0,0 +1,28 @@ +name: 'Checkout Registry' +description: 'Checkout the hyperlane-registry repository and move it to the parent directory' +inputs: + registry_version: + description: 'Override the version of the hyperlane-registry to checkout' +runs: + using: 'composite' + steps: + - name: Read .registryrc if registry_version not provided + shell: bash + run: | + if [ -z "${{ inputs.registry_version }}" ]; then + REGISTRY_VERSION=$(cat .registryrc) + echo "REGISTRY_VERSION=$REGISTRY_VERSION" >> $GITHUB_ENV + else + echo "REGISTRY_VERSION=${{ inputs.registry_version }}" >> $GITHUB_ENV + fi + + - name: Checkout hyperlane-registry + uses: actions/checkout@v4 + with: + repository: hyperlane-xyz/hyperlane-registry + ref: ${{ env.REGISTRY_VERSION }} + path: ./hyperlane-registry + + - name: Move hyperlane-registry to parent directory + shell: bash + run: mv ./hyperlane-registry ../ diff --git a/.github/workflows/monorepo-docker.yml b/.github/workflows/monorepo-docker.yml index 629e08acb..67d4f554f 100644 --- a/.github/workflows/monorepo-docker.yml +++ b/.github/workflows/monorepo-docker.yml @@ -10,9 +10,11 @@ on: - 'typescript/infra/**' - 'Dockerfile' - '.dockerignore' + concurrency: group: build-push-monorepo-${{ github.ref }} cancel-in-progress: true + jobs: check-env: runs-on: ubuntu-latest @@ -66,6 +68,13 @@ jobs: registry: gcr.io username: _json_key password: ${{ secrets.GCLOUD_SERVICE_KEY }} + + - name: Read .registryrc + shell: bash + run: | + REGISTRY_VERSION=$(cat .registryrc) + echo "REGISTRY_VERSION=$REGISTRY_VERSION" >> $GITHUB_ENV + - name: Build and push uses: docker/build-push-action@v5 with: @@ -76,6 +85,5 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max - # To always fetch the latest registry, we use the date as the cache key build-args: | - REGISTRY_CACHE=${{ steps.taggen.outputs.TAG_DATE }} + REGISTRY_COMMIT=${{ env.REGISTRY_VERSION }} diff --git a/.github/workflows/test-skipped.yml b/.github/workflows/test-skipped.yml index 2c73ab5c5..7b4091321 100644 --- a/.github/workflows/test-skipped.yml +++ b/.github/workflows/test-skipped.yml @@ -31,12 +31,6 @@ jobs: - name: Instant pass run: echo "yarn-build job passed" - checkout-registry: - runs-on: ubuntu-latest - steps: - - name: Instant pass - run: echo "checkout-registry job passed" - lint-prettier: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fe6d78004..8584a60f2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,8 +25,6 @@ env: LOG_FORMAT: PRETTY CARGO_TERM_COLOR: always RUST_BACKTRACE: full - # Alongside the monorepo in the directory above the $GITHUB_WORKSPACE. - REGISTRY_URI: ${{ github.workspace }}/../hyperlane-registry jobs: yarn-install: @@ -88,31 +86,6 @@ jobs: - name: build run: yarn build - checkout-registry: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - repository: hyperlane-xyz/hyperlane-registry - ref: main - path: ./hyperlane-registry - - # Put alongside the monorepo in the directory above the $GITHUB_WORKSPACE. - # actions/checkout doesn't allow you to checkout a repository outside of the workspace. - # See https://github.com/actions/checkout/issues/197. - - run: mv ./hyperlane-registry ../ - - # A workaround for relative paths not being supported by actions/cache. - # See https://github.com/actions/upload-artifact/issues/176#issuecomment-1367855630. - - run: echo "REGISTRY_URI_ABSOLUTE=$(realpath $REGISTRY_URI)" >> $GITHUB_ENV - - - name: registry-cache - uses: actions/cache@v4 - with: - path: | - ${{ env.REGISTRY_URI_ABSOLUTE }} - key: hyperlane-registry-${{ github.event.pull_request.head.sha || github.sha }} - lint-prettier: runs-on: ubuntu-latest needs: [yarn-install] @@ -145,7 +118,7 @@ jobs: yarn-test: runs-on: ubuntu-latest - needs: [yarn-build, checkout-registry] + needs: [yarn-build] steps: - uses: actions/checkout@v4 with: @@ -164,24 +137,15 @@ jobs: !./rust key: ${{ github.event.pull_request.head.sha || github.sha }} - # A workaround for relative paths not being supported by actions/cache. - # See https://github.com/actions/upload-artifact/issues/176#issuecomment-1367855630. - - run: echo "REGISTRY_URI_ABSOLUTE=$(realpath $REGISTRY_URI)" >> $GITHUB_ENV - - - name: registry-cache - uses: actions/cache@v4 - with: - path: | - ${{ env.REGISTRY_URI_ABSOLUTE }} - key: hyperlane-registry-${{ github.event.pull_request.head.sha || github.sha }} - fail-on-cache-miss: true + - name: Checkout registry + uses: ./.github/actions/checkout-registry - name: Unit Tests run: yarn test:ci agent-configs: runs-on: ubuntu-latest - needs: [yarn-build, checkout-registry] + needs: [yarn-build] strategy: fail-fast: false matrix: @@ -208,17 +172,8 @@ jobs: !./rust key: ${{ github.event.pull_request.head.sha || github.sha }} - # A workaround for relative paths not being supported by actions/cache. - # See https://github.com/actions/upload-artifact/issues/176#issuecomment-1367855630. - - run: echo "REGISTRY_URI_ABSOLUTE=$(realpath $REGISTRY_URI)" >> $GITHUB_ENV - - - name: registry-cache - uses: actions/cache@v4 - with: - path: | - ${{ env.REGISTRY_URI_ABSOLUTE }} - key: hyperlane-registry-${{ github.event.pull_request.head.sha || github.sha }} - fail-on-cache-miss: true + - name: Checkout registry + uses: ./.github/actions/checkout-registry - name: Generate ${{ matrix.environment }} agent config run: | @@ -233,7 +188,7 @@ jobs: e2e-matrix: runs-on: larger-runner if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.base_ref == 'main') || github.event_name == 'merge_group' - needs: [yarn-build, checkout-registry] + needs: [yarn-build] strategy: matrix: e2e-type: [cosmwasm, non-cosmwasm] @@ -294,17 +249,8 @@ jobs: !./rust key: ${{ github.event.pull_request.head.sha || github.sha }} - # A workaround for relative paths not being supported by actions/cache. - # See https://github.com/actions/upload-artifact/issues/176#issuecomment-1367855630. - - run: echo "REGISTRY_URI_ABSOLUTE=$(realpath $REGISTRY_URI)" >> $GITHUB_ENV - - - name: registry-cache - uses: actions/cache@v4 - with: - path: | - ${{ env.REGISTRY_URI_ABSOLUTE }} - key: hyperlane-registry-${{ github.event.pull_request.head.sha || github.sha }} - fail-on-cache-miss: true + - name: Checkout registry + uses: ./.github/actions/checkout-registry - name: agent tests with CosmWasm run: cargo test --release --package run-locally --bin run-locally --features cosmos test-utils -- cosmos::test --nocapture @@ -336,7 +282,6 @@ jobs: prebuild-cli-e2e: runs-on: larger-runner if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.base_ref == 'main') || github.event_name == 'merge_group' - needs: [checkout-registry] steps: - uses: actions/checkout@v4 with: @@ -450,24 +395,15 @@ jobs: !./rust key: ${{ github.event.pull_request.head.sha || github.sha }} - # A workaround for relative paths not being supported by actions/cache. - # See https://github.com/actions/upload-artifact/issues/176#issuecomment-1367855630. - - run: echo "REGISTRY_URI_ABSOLUTE=$(realpath $REGISTRY_URI)" >> $GITHUB_ENV - - - name: registry-cache - uses: actions/cache@v4 - with: - path: | - ${{ env.REGISTRY_URI_ABSOLUTE }} - key: hyperlane-registry-${{ github.event.pull_request.head.sha || github.sha }} - fail-on-cache-miss: true + - name: Checkout registry + uses: ./.github/actions/checkout-registry - name: cli e2e tests run: ./typescript/cli/ci-test.sh ${{ matrix.test-type }} env-test: runs-on: ubuntu-latest - needs: [yarn-build, checkout-registry] + needs: [yarn-build] strategy: fail-fast: false matrix: @@ -495,17 +431,8 @@ jobs: !./rust key: ${{ github.event.pull_request.head.sha || github.sha }} - # A workaround for relative paths not being supported by actions/cache. - # See https://github.com/actions/upload-artifact/issues/176#issuecomment-1367855630. - - run: echo "REGISTRY_URI_ABSOLUTE=$(realpath $REGISTRY_URI)" >> $GITHUB_ENV - - - name: registry-cache - uses: actions/cache@v4 - with: - path: | - ${{ env.REGISTRY_URI_ABSOLUTE }} - key: hyperlane-registry-${{ github.event.pull_request.head.sha || github.sha }} - fail-on-cache-miss: true + - name: Checkout registry + uses: ./.github/actions/checkout-registry - name: Fork test ${{ matrix.environment }} ${{ matrix.module }} ${{ matrix.chain }} deployment run: cd typescript/infra && ./fork.sh ${{ matrix.environment }} ${{ matrix.module }} ${{ matrix.chain }} diff --git a/.registryrc b/.registryrc new file mode 100644 index 000000000..826e14246 --- /dev/null +++ b/.registryrc @@ -0,0 +1 @@ +v2.1.1 diff --git a/Dockerfile b/Dockerfile index 763e1186f..1a03f74d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,8 +29,7 @@ COPY solidity ./solidity RUN yarn build ENV REGISTRY_URI="/hyperlane-registry" -# To allow us to avoid caching the registry clone, we use a build-time arg to force -# the below steps to be re-run if this arg is changed. -ARG REGISTRY_CACHE="default" - -RUN git clone https://github.com/hyperlane-xyz/hyperlane-registry.git "$REGISTRY_URI" +ARG REGISTRY_COMMIT="main" +RUN git clone https://github.com/hyperlane-xyz/hyperlane-registry.git "$REGISTRY_URI" \ + && cd "$REGISTRY_URI" \ + && git checkout "$REGISTRY_COMMIT"