Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/contracts-publish-compiled-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,9 @@ jobs:
files: |
${{ steps.package.outputs.tar_path }}

- name: Write contract build SHA to file
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'workflow_dispatch' && github.event.inputs.create_release == 'true') }}
run: |
# most up to date build SHA for contracts for the current version, to be used by other workflows/repos
# note: the hash of the built artifacts is available on after it gets merged in the main branch as a release
echo "${{ steps.get_sha.outputs.short_sha }}" > ../../deployment/utils/contract_build_sha
1 change: 1 addition & 0 deletions deployment/utils/contract_build_sha
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f6f0d2146b76
18 changes: 18 additions & 0 deletions deployment/utils/contract_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package utils

import (
"os"
"strings"
)

// GetContractBuildSHA returns the most up-to-date build SHA for contracts for the current version, to be used by other workflows/repos
//
// note: the hash of the built artifacts is automatically modified only after a branch gets merged in the main branch as a release
func GetContractBuildSHA() (string, error) {
const shaFile = "contract_build_sha"
data, err := os.ReadFile(shaFile)
if err != nil {
return "", err
}
return strings.TrimSpace(string(data)), nil
}
25 changes: 25 additions & 0 deletions deployment/utils/contract_version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package utils

import (
"os"
"strings"
"testing"
)

func TestGetContractBuildSHA(t *testing.T) {
const shaFile = "contract_build_sha"

data, err := os.ReadFile(shaFile)
if err != nil {
t.Skipf("%s not found, skipping test", shaFile)
}
expected := strings.TrimSpace(string(data))

sha, err := GetContractBuildSHA()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if sha != expected {
t.Errorf("expected %s, got %s", expected, sha)
}
}
Loading