Skip to content

Commit

Permalink
Refactor GitHub setup-go action (stellar#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio authored Jun 20, 2024
1 parent 6f92bbf commit 0083ced
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 84 deletions.
90 changes: 45 additions & 45 deletions .github/actions/setup-go/action.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
name: 'Setup the Go environment'
description: 'Installs go and restores/saves the build/module cache'
inputs:
go-version:
required: true
runs:
using: "composite"
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ inputs.go-version }}
stable: ${{ !(contains(inputs.go-version, 'beta') || contains(inputs.go-version, 'rc')) }}
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
# unfortunately we cannot use the provided caching because it uses the
# same cache for all workflows/jobs, leading to undesired cache clashes,
# causing uncached test runs etc ...
# You can see the cache key at https://github.com/actions/setup-go/blob/4e0b6c77c6448caafaff5eed51516cad78e7639a/src/cache-restore.ts#L34
# There is a ticket to add prefixes for the cache, which should solve it https://github.com/actions/setup-go/issues/358
cache: false

# Restore original modification time of files based on the date of the most
# recent commit that modified them as mtimes affect the Go test cache.
- name: Restore modification time of checkout files
shell: bash
run: |
# Set a base, fixed modification time of all directories.
# git-restore-mtime doesn't set the mtime of all directories.
# (see https://github.com/MestreLion/git-tools/issues/47 for details)
touch -m -t '201509301646' $(find . -type d -not -path '.git/*')
# Restore original modification time from git. git clone sets the
# modification time to the current time, but Go tests that access fixtures
# get invalidated if their modification times change.
sudo apt-get install -y git-restore-mtime
git restore-mtime
# Restore original modification time of files based on the date of the most
# recent commit that modified them as mtimes affect the Go test cache.
# See https://github.com/golang/go/issues/58571 for details
- name: Restore modification time of checkout files
uses: chetan/git-restore-mtime-action@075f9bc9d159805603419d50f794bd9f33252ebe

# The PREFIX must uniquely identify the specific instance of a job executing.
- shell: bash
run: echo 'PREFIX=${{ github.workflow }}-${{ github.job }}-${{ runner.os }}-${{ inputs.go-version }}-matrix(${{ join(matrix.*,'|') }})' >> $GITHUB_ENV

# Cache the Go Modules downloaded during the job.
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ env.PREFIX }}-go-mod-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ env.PREFIX }}-go-mod-
# KEY_PREFIX must uniquely identify the specific instance of a job executing.
- shell: bash
run: |
echo 'KEY_PREFIX=${{ github.workflow }}-${{ github.job }}-${{ runner.os }}-${{ inputs.go-version }}-matrix(${{ join(matrix.*,'|') }})' >> $GITHUB_OUTPUT
echo "GOCACHE=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "GOMODCACHE=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
if [ ${{ runner.os }} != 'Windows' ]; then echo SUDO='sudo' >> $GITHUB_OUTPUT; fi
id: variables

# Cache any build and test artifacts during the job, which will speed up
# rebuilds and cause test runs to skip tests that have no reason to rerun.
- uses: actions/cache@v2
with:
path: ~/.cache/go-build
key: ${{ env.PREFIX }}-go-build-${{ github.ref }}-${{ hashFiles('**', '!.git') }}
restore-keys: |
${{ env.PREFIX }}-go-build-${{ github.ref }}-
${{ env.PREFIX }}-go-build-
# Cache the Go Modules downloaded during the job.
- uses: actions/cache@v4
with:
path: ${{ steps.variables.outputs.GOMODCACHE }}
key: ${{ steps.variables.outputs.KEY_PREFIX }}-go-mod-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ steps.variables.outputs.KEY_PREFIX }}-go-mod-

# Cache any build and test artifacts during the job, which will speed up
# rebuilds and cause test runs to skip tests that have no reason to rerun.
- uses: actions/cache@v4
with:
path: ${{ steps.variables.outputs.GOCACHE }}
key: ${{ steps.variables.outputs.KEY_PREFIX }}-go-build-${{ github.ref }}-${{ hashFiles('**', '!.git') }}
restore-keys: |
${{ steps.variables.outputs.KEY_PREFIX }}-go-build-${{ github.ref }}-
${{ steps.variables.outputs.KEY_PREFIX }}-go-build-
# Reset the cache for master/protected branches, to ensure they build and run the tests from zero
# and that the module cache is cleaned (otherwise it accumulates orphan dependencies over time).
- if: github.ref_protected
shell: bash
run: ${{ steps.variables.outputs.SUDO }} rm -rf ${{ steps.variables.outputs.GOMODCACHE }} ${{ steps.variables.outputs.GOCACHE }}

# Reset the cache for master/protected branches, to ensure they build and run the tests from zero
# and that the module cache is cleaned (otherwise it accumulates orphan dependencies over time).
- if: github.ref_protected
shell: bash
run: sudo rm -rf ~/.cache/go-build ~/go/pkg/mod
12 changes: 6 additions & 6 deletions .github/workflows/dependency-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Dependency sanity checker

on:
push:
branches: [main, release/**]
branches: [ main, release/** ]
pull_request:

defaults:
Expand All @@ -13,14 +13,14 @@ jobs:
dependency-sanity-checker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: rustup update
- uses: actions/setup-go@v3
with:
go-version: 1.22
- uses: stellar/actions/rust-cache@main
- uses: ./.github/actions/setup-go
- run: scripts/check-dependencies.bash

validate-rust-git-rev-deps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: stellar/actions/rust-check-git-rev-deps@main
18 changes: 9 additions & 9 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: Soroban Tools e2e

on:
push:
branches: [main, release/**]
branches: [ main, release/** ]
pull_request:

jobs:
integration:
name: System tests
strategy:
matrix:
scenario-filter: ["^TestDappDevelop$/^.*$"]
scenario-filter: [ "^TestDappDevelop$/^.*$" ]
runs-on: ubuntu-latest-4-cores
env:
# the gh tag of system-test repo version to run
Expand All @@ -28,7 +28,7 @@ jobs:
# or set SYSTEM_TEST_CORE_GIT_REF to empty, and set SYSTEM_TEST_CORE_IMAGE
# to pull a pre-compiled image from dockerhub instead
SYSTEM_TEST_CORE_IMAGE: stellar/stellar-core:20
SYSTEM_TEST_CORE_IMAGE_BIN_PATH: /usr/bin/stellar-core
SYSTEM_TEST_CORE_IMAGE_BIN_PATH: /usr/bin/stellar-core

# sets the version of rust toolchain that will be pre-installed in the
# test runtime environment, tests invoke rustc/cargo
Expand All @@ -42,8 +42,8 @@ jobs:
# option #2, set the version of stellar-sdk used as a ref to a gh repo if
# a value is set on SYSTEM_TEST_JS_STELLAR_SDK_GH_REPO, it takes
# precedence over any SYSTEM_TEST_JS_STELLAR_SDK_NPM_VERSION
SYSTEM_TEST_JS_STELLAR_SDK_GH_REPO:
SYSTEM_TEST_JS_STELLAR_SDK_GH_REF:
SYSTEM_TEST_JS_STELLAR_SDK_GH_REPO:
SYSTEM_TEST_JS_STELLAR_SDK_GH_REF:

# the version of rs-stellar-xdr to use for quickstart
SYSTEM_TEST_RS_XDR_GIT_REF: v20.0.2
Expand All @@ -59,18 +59,18 @@ jobs:
SYSTEM_TEST_SOROBAN_EXAMPLES_GIT_HASH: "v20.0.0"
SYSTEM_TEST_SOROBAN_EXAMPLES_GIT_REPO: "https://github.com/stellar/soroban-examples.git"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
name: checkout system-test
with:
repository: stellar/system-test
ref: ${{ env.SYSTEM_TEST_GIT_REF }}
path: system-test
- uses: actions/checkout@v3
- uses: actions/checkout@v4
name: checkout soroban-tools
with:
repository: stellar/soroban-tools
path: soroban-tools
- uses: actions/checkout@v3
- uses: actions/checkout@v4
name: checkout soroban-rpc
with:
repository: stellar/soroban-rpc
Expand All @@ -81,7 +81,7 @@ jobs:
run: |
rm -rf $GITHUB_WORKSPACE/system-test/js-stellar-sdk;
- if: ${{ env.SYSTEM_TEST_JS_STELLAR_SDK_GH_REPO != ''}}
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: ${{ env.SYSTEM_TEST_JS_STELLAR_SDK_GH_REPO }}
ref: ${{ env.SYSTEM_TEST_JS_STELLAR_SDK_GH_REF }}
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,19 @@ permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read
# Optional: allow write access to checks to allow the action to annotate code in the PR.
# Optional: allow the action to annotate code in the PR.
checks: write

jobs:
golangci-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # version v3.0.2
uses: actions/checkout@v4
with:
fetch-depth: 0 # required for new-from-rev option in .golangci.yml

- name: Setup GO
uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f # version v3.3.0
with:
go-version: '>=1.22.1'
- uses: ./.github/actions/setup-go

- uses: stellar/actions/rust-cache@main
- name: Build libpreflight
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: rustup update
- uses: stellar/actions/rust-cache@main
- run: make rust-check
Expand Down
23 changes: 6 additions & 17 deletions .github/workflows/soroban-rpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,20 @@ jobs:
strategy:
matrix:
os: [ ubuntu-20.04, ubuntu-22.04 ]
go: [ 1.22 ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
# For pull requests, build and test the PR head not a merge of the PR with the destination.
ref: ${{ github.event.pull_request.head.sha || github.ref }}
# We need to full history for git-restore-mtime to know what modification dates to use.
# Otherwise, the Go test cache will fail (due to the modification time of fixtures changing).
fetch-depth: "0"
- uses: ./.github/actions/setup-go
with:
go-version: ${{ matrix.go }}
- run: rustup update
- uses: stellar/actions/rust-cache@main
- run: make build-libpreflight
- run: go test -race -cover -timeout 25m -v ./cmd/soroban-rpc/...
- run: go test -race -timeout 25m ./cmd/soroban-rpc/...

build:
name: Build
Expand All @@ -55,13 +52,8 @@ jobs:
go_arch: amd64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
# we cannot use our own ./.github/actions/setup-go action
# because it uses apt-get and some OSs (e.g. windows) don't have it
- uses: actions/setup-go@v3
with:
go-version: 1.22

- uses: actions/checkout@v4
- uses: ./.github/actions/setup-go
# On windows, make sure we have the same compiler (linker) used by rust.
# This is important since the symbols names won't match otherwise.
- if: matrix.os == 'windows-latest'
Expand Down Expand Up @@ -102,7 +94,6 @@ jobs:
strategy:
matrix:
os: [ ubuntu-20.04, ubuntu-22.04 ]
go: [ 1.22 ]
protocol-version: [ 20, 21 ]
runs-on: ${{ matrix.os }}
env:
Expand All @@ -114,7 +105,7 @@ jobs:
PROTOCOL_21_CORE_DEBIAN_PKG_VERSION: 21.0.1-1897.dfd3dbff1.focal
PROTOCOL_21_CORE_DOCKER_IMG: stellar/unsafe-stellar-core:21.0.1-1897.dfd3dbff1.focal
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
# For pull requests, build and test the PR head not a merge of the PR with the destination.
ref: ${{ github.event.pull_request.head.sha || github.ref }}
Expand All @@ -123,8 +114,6 @@ jobs:
fetch-depth: "0"

- uses: ./.github/actions/setup-go
with:
go-version: ${{ matrix.go }}

- name: Pull and set Stellar Core image
shell: bash
Expand Down Expand Up @@ -179,4 +168,4 @@ jobs:

- name: Run Soroban RPC Integration Tests
run: |
go test -race -timeout 20m ./cmd/soroban-rpc/internal/integrationtest/...
go test -race -timeout 20m ./cmd/soroban-rpc/internal/integrationtest/...

0 comments on commit 0083ced

Please sign in to comment.