Skip to content

Commit 2ad1c7b

Browse files
committed
INFRA-787 - switch publish.yml to shared workflow
1 parent 5c25cba commit 2ad1c7b

File tree

2 files changed

+63
-59
lines changed

2 files changed

+63
-59
lines changed

.github/workflows/publish.yml

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,87 @@
1-
name: Publish image and deploy to staging
1+
name: Build image from main and deploy to staging
22

33
on:
44
push:
55
branches:
66
- main
77

88
jobs:
9-
publish:
9+
prepare-variables:
1010
runs-on: ubuntu-24.04
11+
timeout-minutes: 5
1112
permissions:
12-
id-token: write # needed by aws-actions/configure-aws-credentials
1313
contents: read
14-
env:
15-
AWS_REGION: eu-west-1
14+
15+
outputs:
16+
image_tag: ${{ steps.prepare-variables.outputs.IMAGE_TAG }}
17+
ecr_tags: ${{ steps.prepare-variables.outputs.ECR_TAGS }}
1618

1719
steps:
18-
- name: Checkout repository
19-
uses: actions/checkout@v5
20-
21-
- name: Set up QEMU
22-
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
23-
with:
24-
platforms: arm64
20+
# Required by prepare-variables
21+
- uses: actions/checkout@v6
2522

26-
- name: Set up Docker Buildx
27-
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
28-
with:
29-
install: true
23+
- name: Prepare variables
24+
id: prepare-variables
25+
env:
26+
# github.ref_name is the plain (no prefix) branch or tag name that
27+
# triggered the workflow (e.g. "main", "v1.2.3").
28+
# We are passing it through env to prevent script injection via crafted
29+
# branch names (e.g. a branch named `; rm -rf /` would be interpolated
30+
# directly into the shell script if using ${{ }} inline).
31+
REF_NAME: ${{ github.ref_name }}
32+
run: |
33+
set -x
3034
31-
- name: Configure AWS credentials
32-
uses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838 # v5.0.0
33-
with:
34-
role-to-assume: arn:aws:iam::${{ secrets.AWS_STAGING_ACCOUNT_ID }}:role/${{ secrets.AWS_APPS_SALEOR_MCP_STAGING_CICD_ROLE_NAME }}
35-
aws-region: ${{ env.AWS_REGION }}
35+
image_tag_unique="${REF_NAME}-$(git rev-parse --short HEAD)"
36+
ecr_tags="${image_tag_unique},${REF_NAME}-latest"
3637
37-
- id: ecr-login
38-
name: Login to Amazon ECR
39-
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076 # v2.0.1
40-
with:
41-
registries: ${{ secrets.AWS_ECR_ACCOUNT }}
38+
echo "IMAGE_TAG=${image_tag_unique}" >> $GITHUB_OUTPUT
39+
echo "ECR_TAGS=${ecr_tags}" >> $GITHUB_OUTPUT
4240
43-
- name: Evaluate image tags
44-
env:
45-
IMAGE_REPOSITORY: ${{ steps.ecr-login.outputs.registry }}/${{ secrets.ECR_REPOSITORY }}
46-
BRANCH_IMAGE_TAG: ${{ github.ref_name }}
47-
run: |
48-
UNIQUE_IMAGE_TAG=${BRANCH_IMAGE_TAG}-$(git rev-parse --short HEAD)
4941
50-
IMAGE_TAGS=${IMAGE_REPOSITORY}:${BRANCH_IMAGE_TAG},${IMAGE_REPOSITORY}:${UNIQUE_IMAGE_TAG}
42+
build-push:
43+
needs: [prepare-variables]
44+
uses: saleor/saleor-internal-actions/.github/workflows/build-push-image-multi-platform.yaml@9c7a814c011945f26f0aa1191fc9c62de45477c2 # v1.7.0
5145

52-
echo "UNIQUE_IMAGE_TAG=${UNIQUE_IMAGE_TAG}" >> $GITHUB_ENV
53-
echo "IMAGE_TAGS=${IMAGE_TAGS}" >> $GITHUB_ENV
46+
permissions:
47+
contents: read
48+
id-token: write # needed for AWS/ECR login
49+
packages: write # needed for GHCR (not used, but required permission)
5450

55-
- name: Build and push
56-
timeout-minutes: 20
57-
uses: docker/build-push-action@v4
51+
with:
52+
tags: ${{ needs.prepare-variables.outputs.ecr_tags }}
53+
enable-aws-ecr: true
54+
aws-ecr-region: eu-west-1
55+
56+
secrets:
57+
oci-full-repository: ${{ secrets.AWS_ECR_ACCOUNT }}.dkr.ecr.eu-west-1.amazonaws.com/${{ secrets.ECR_REPOSITORY }}
58+
aws-ecr-role-to-assume: arn:aws:iam::${{ secrets.AWS_STAGING_ACCOUNT_ID }}:role/${{ secrets.AWS_APPS_SALEOR_MCP_STAGING_CICD_ROLE_NAME }}
59+
aws-ecr-registries: ${{ secrets.AWS_ECR_ACCOUNT }}
60+
61+
deploy:
62+
needs: [prepare-variables, build-push]
63+
runs-on: ubuntu-24.04
64+
permissions: {}
65+
66+
steps:
67+
- name: Get Token
68+
id: get-token
69+
uses: saleor/saleor-internal-actions/request-vault-token@6a0fa7c073b3857a11d414f25a149065fe5a0fcf # v1.4.0
5870
with:
59-
context: .
60-
platforms: linux/amd64,linux/arm64
61-
push: true
62-
tags: ${{ env.IMAGE_TAGS }}
63-
cache-from: type=gha,scope=buildkit-master
64-
cache-to: type=gha,scope=buildkit-master
71+
vault-url: ${{ secrets.VAULT_URL }}
72+
vault-jwt: ${{ secrets.VAULT_JWT }}
6573

6674
- name: Trigger staging deployment
75+
env:
76+
GITHUB_TOKEN: ${{ steps.get-token.outputs.token }}
77+
IMAGE_TAG: ${{ needs.prepare-variables.outputs.image_tag }}
6778
run: |
68-
export GITHUB_TOKEN=$( \
69-
curl --request GET --url ${{ secrets.VAULT_URL}} --header "Authorization: JWT ${{ secrets.VAULT_JWT }}" | jq -r .token \
70-
)
71-
72-
echo "::add-mask::$GITHUB_TOKEN"
73-
7479
payload=$(
75-
jq --arg image_tag "$UNIQUE_IMAGE_TAG" -n '{
80+
jq -n --arg image_tag "$IMAGE_TAG" '{
7681
"event_type": "saleor-mcp-staging",
7782
"client_payload": {
7883
"image_tag": $image_tag
7984
}
8085
}'
8186
)
82-
83-
gh api /repos/saleor/saleor-cloud-deployments/dispatches --input <(echo "$payload")
87+
gh api /repos/saleor/saleor-cloud-deployments/dispatches --input - <<< "$payload"

.github/workflows/test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ jobs:
1414
name: "Run linters and tests"
1515

1616
steps:
17-
- uses: actions/checkout@v4
18-
17+
- uses: actions/checkout@v6
18+
1919
- name: Install uv
2020
uses: astral-sh/setup-uv@v4
2121
with:
2222
version: "latest"
23-
23+
2424
- name: Install dependencies
2525
run: uv sync --dev
26-
26+
2727
- name: Run linting
2828
run: uv run ruff check .
29-
29+
3030
- name: Run typechecker
3131
run: uv run ty check
32-
32+
3333
- name: Run tests
3434
run: uv run pytest

0 commit comments

Comments
 (0)