Skip to content

Commit 088d05a

Browse files
committed
fix(ci): get latest tag for catalog remote tests
1 parent f295b3c commit 088d05a

2 files changed

Lines changed: 84 additions & 6 deletions

File tree

.github/workflows/pull-request-main.yml

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,54 @@ jobs:
7979
id-token: write
8080
contents: read
8181
actions: read
82-
env:
83-
CATALOG_SERVICE_IMAGE: ${{ secrets.AWS_ACCOUNT_NUMBER_PROD }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/op-catalog-service:latest
8482
steps:
83+
- name: Checkout code
84+
uses: actions/checkout@v4
85+
86+
- name: Configure AWS credentials for ECR
87+
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
88+
with:
89+
role-to-assume: ${{ secrets.ECR_READ_ROLE_ARN }}
90+
aws-region: ${{ secrets.AWS_REGION }}
91+
92+
- name: Get latest catalog service tag from ECR
93+
id: get-catalog-tag
94+
run: |
95+
# Fetch the latest image tag from ECR based on push date
96+
# Get the most recently pushed image's tags and find the highest semver tag
97+
LATEST_TAG=$(aws ecr describe-images \
98+
--repository-name op-catalog-service \
99+
--region ${{ secrets.AWS_REGION }} \
100+
--registry-id ${{ secrets.AWS_ACCOUNT_NUMBER_PROD }} \
101+
--query 'reverse(sort_by(imageDetails,& imagePushedAt))' \
102+
--output json | \
103+
jq -r '
104+
.[] |
105+
select(.imageTags != null) |
106+
.imageTags[] |
107+
select(test("^v[0-9]+\\.[0-9]+\\.[0-9]+$"))
108+
' | \
109+
sed 's/^v//' | \
110+
sort -t. -k1,1n -k2,2n -k3,3n | \
111+
tail -1 | \
112+
sed 's/^/v/')
113+
114+
if [[ -z "${LATEST_TAG}" ]]; then
115+
echo "::error::Could not find a valid semantic version tag in ECR"
116+
exit 1
117+
fi
118+
119+
echo "Latest catalog service tag from ECR: ${LATEST_TAG}"
120+
echo "tag=${LATEST_TAG}" >> "${GITHUB_OUTPUT}"
121+
85122
- name: Pull Catalog Service ECR Image
86123
uses: smartcontractkit/.github/actions/pull-private-ecr-image@2f8f0baf38e46140c6a119eb551a56eaaabcc09e # pull-private-ecr-image@1.0.0
87124
with:
88125
aws-account-number: ${{ secrets.AWS_ACCOUNT_NUMBER_PROD }}
89126
aws-region: ${{ secrets.AWS_REGION }}
90127
aws-role-arn: ${{ secrets.ECR_READ_ROLE_ARN }}
91128
ecr-repository: "op-catalog-service"
92-
image-tag: "latest"
129+
image-tag: ${{ steps.get-catalog-tag.outputs.tag }}
93130

94131
- name: Run Catalog Remote Integration Tests
95132
uses: smartcontractkit/.github/actions/ci-test-go@dfcba48f05933158428bce867d790e3d5a9baa6b # ci-test-go@1.1.0
@@ -98,6 +135,8 @@ jobs:
98135
go-test-cmd: cd datastore/catalog/remote && go test -v -race -timeout 10m -gcflags=all=-d=checkptr=0 -coverprofile=../../../coverage.txt
99136
use-go-cache: true
100137
artifact-name: catalog-remote-tests
138+
env:
139+
CATALOG_SERVICE_IMAGE: ${{ secrets.AWS_ACCOUNT_NUMBER_PROD }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/op-catalog-service:${{ steps.get-catalog-tag.outputs.tag }}
101140

102141
sonarqube:
103142
name: Sonar Scan

.github/workflows/schedule-main.yml

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,54 @@ jobs:
7575
id-token: write
7676
contents: read
7777
actions: read
78-
env:
79-
CATALOG_SERVICE_IMAGE: ${{ secrets.AWS_ACCOUNT_NUMBER_PROD }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/op-catalog-service:latest
8078
steps:
79+
- name: Checkout code
80+
uses: actions/checkout@v4
81+
82+
- name: Configure AWS credentials for ECR
83+
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
84+
with:
85+
role-to-assume: ${{ secrets.ECR_READ_ROLE_ARN }}
86+
aws-region: ${{ secrets.AWS_REGION }}
87+
88+
- name: Get latest catalog service tag from ECR
89+
id: get-catalog-tag
90+
run: |
91+
# Fetch the latest image tag from ECR based on push date
92+
# Get the most recently pushed image's tags and find the highest semver tag
93+
LATEST_TAG=$(aws ecr describe-images \
94+
--repository-name op-catalog-service \
95+
--region ${{ secrets.AWS_REGION }} \
96+
--registry-id ${{ secrets.AWS_ACCOUNT_NUMBER_PROD }} \
97+
--query 'reverse(sort_by(imageDetails,& imagePushedAt))' \
98+
--output json | \
99+
jq -r '
100+
.[] |
101+
select(.imageTags != null) |
102+
.imageTags[] |
103+
select(test("^v[0-9]+\\.[0-9]+\\.[0-9]+$"))
104+
' | \
105+
sed 's/^v//' | \
106+
sort -t. -k1,1n -k2,2n -k3,3n | \
107+
tail -1 | \
108+
sed 's/^/v/')
109+
110+
if [[ -z "${LATEST_TAG}" ]]; then
111+
echo "::error::Could not find a valid semantic version tag in ECR"
112+
exit 1
113+
fi
114+
115+
echo "Latest catalog service tag from ECR: ${LATEST_TAG}"
116+
echo "tag=${LATEST_TAG}" >> "${GITHUB_OUTPUT}"
117+
81118
- name: Pull Catalog Service ECR Image
82119
uses: smartcontractkit/.github/actions/pull-private-ecr-image@2f8f0baf38e46140c6a119eb551a56eaaabcc09e # pull-private-ecr-image@1.0.0
83120
with:
84121
aws-account-number: ${{ secrets.AWS_ACCOUNT_NUMBER_PROD }}
85122
aws-region: ${{ secrets.AWS_REGION }}
86123
aws-role-arn: ${{ secrets.ECR_READ_ROLE_ARN }}
87124
ecr-repository: "op-catalog-service"
88-
image-tag: "latest"
125+
image-tag: ${{ steps.get-catalog-tag.outputs.tag }}
89126

90127
- name: Run Catalog Remote Integration Tests
91128
uses: smartcontractkit/.github/actions/ci-test-go@dfcba48f05933158428bce867d790e3d5a9baa6b # ci-test-go@1.1.0
@@ -94,6 +131,8 @@ jobs:
94131
go-test-cmd: cd datastore/catalog/remote && go test -v -race -timeout 10m -gcflags=all=-d=checkptr=0 -coverprofile=../../../coverage.txt
95132
use-go-cache: true
96133
artifact-name: catalog-remote-tests
134+
env:
135+
CATALOG_SERVICE_IMAGE: ${{ secrets.AWS_ACCOUNT_NUMBER_PROD }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/op-catalog-service:${{ steps.get-catalog-tag.outputs.tag }}
97136

98137
sonarqube:
99138
name: Sonar Scan

0 commit comments

Comments
 (0)