Skip to content

Saleor Core: the high performance, composable, headless commerce API.

build: add environment and permissions everywhere (#18925)

Mikaildfa430ac5cff
diff --git a/.github/workflows/bump-dependencies.yml b/.github/workflows/bump-dependencies.yml
index 52a5f1a06e..7e45e01456 100644
--- a/.github/workflows/bump-dependencies.yml
+++ b/.github/workflows/bump-dependencies.yml
@@ -3,22 +3,31 @@ name: Bump dependencies
on:
workflow_dispatch:
schedule:
- - cron: '0 8 1 * *' # At 08:00 on day-of-month 1
+ - cron: "0 8 1 * *" # At 08:00 on day-of-month 1
+
+permissions: {}
jobs:
bump-dependencies:
if: ${{ github.event_name != 'schedule' || github.repository == 'saleor/saleor' }}
runs-on: ubuntu-latest
+ permissions:
+ contents: write
+ pull-requests: write
+
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v6
with:
- python-version: '3.12'
+ python-version: "3.12"
- uses: astral-sh/setup-uv@b75a909f75acd358c2196fb9a5f1299a9a8868a4 # v6.0.0
with:
- enable-cache: true
+ # Do not allow cache as other actions could write to that cache
+ # for lateral movement, and the workflow runs too infrequently
+ # thus there isn't any benefit.
+ enable-cache: false
- run: python -m pip install pre-commit
- run: uv lock --upgrade
@@ -26,13 +35,13 @@ jobs:
- run: git status
- name: Create Pull Request
- uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
+ uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: bump-dependencies
delete-branch: true
commit-message: Bump dependencies
- title: 'Bump dependencies'
+ title: "Bump dependencies"
body: |
Monthly update of backend dependencies.
labels: |
diff --git a/.github/workflows/changelog-check.yml b/.github/workflows/changelog-check.yml
index d50ed176df..c1fb9465c3 100644
--- a/.github/workflows/changelog-check.yml
+++ b/.github/workflows/changelog-check.yml
@@ -2,19 +2,24 @@ name: "Changelog check"
on:
pull_request:
branches:
- - 'main'
+ - "main"
# The specific activity types are listed here to include "labeled" and "unlabeled"
# (which are not included by default for the "pull_request" trigger).
# This is needed to allow skipping enforcement of the changelog in PRs with specific labels,
# as defined in the (optional) "skipLabels" property.
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]
+permissions: {}
jobs:
# Enforces the update of a changelog file on every pull request
changelog:
runs-on: ubuntu-latest
+
+ permissions:
+ contents: read
+
steps:
- - uses: dangoslen/changelog-enforcer@204e7d3ef26579f4cd0fd759c57032656fdf23c7
- with:
- skipLabels: "skip changelog,dependencies,bot"
+ - uses: dangoslen/changelog-enforcer@204e7d3ef26579f4cd0fd759c57032656fdf23c7
+ with:
+ skipLabels: "skip changelog,dependencies,bot"
diff --git a/.github/workflows/check-licenses.yaml b/.github/workflows/check-licenses.yaml
index 0073fb30ef..ac9366afb9 100644
--- a/.github/workflows/check-licenses.yaml
+++ b/.github/workflows/check-licenses.yaml
@@ -18,12 +18,14 @@ on:
- "**/pnpm-lock.yaml"
- "**/package-lock.json"
+permissions: {}
+
jobs:
default:
permissions:
contents: read
pull-requests: write
- uses: saleor/saleor-internal-actions/.github/workflows/run-license-check.yaml@v1
+ uses: saleor/saleor-internal-actions/.github/workflows/run-license-check.yaml@49a069ae9731cfccf3a1033fe1da4e3da84f4f2a # v1.11.0
with:
# List of ecosystems to scan.
ecosystems: >-
diff --git a/.github/workflows/create-tag-with-release-pr.yml b/.github/workflows/create-tag-with-release-pr.yml
index efbe752b18..f345edf023 100644
--- a/.github/workflows/create-tag-with-release-pr.yml
+++ b/.github/workflows/create-tag-with-release-pr.yml
@@ -2,17 +2,27 @@ name: Create release tag on release PR merge
on:
pull_request:
types:
- - closed
+ - closed
+
+permissions: {}
jobs:
create-release-tag:
runs-on: ubuntu-24.04
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release')
+
+ permissions:
+ # Needed to write tags & releases
+ # Docs: https://docs.github.com/en/rest/authentication/permissions-required-for-github-apps?apiVersion=2022-11-28#repository-permissions-for-contents
+ contents: write
+
env:
GH_REF: ${{ github.event.pull_request.head.ref }}
GH_TOKEN: ${{ github.token }}
+
outputs:
version: ${{ steps.set-version.outputs.VERSION }}
+
steps:
- name: Set version
id: set-version
@@ -62,24 +72,31 @@ jobs:
gh release create -d "$VERSION" --repo="$GITHUB_REPOSITORY" --latest="$IS_LATEST" --generate-notes --verify-tag
publish:
- needs:
- - create-release-tag
+ needs: [create-release-tag]
uses: ./.github/workflows/publish-containers.yml
+
+ permissions:
+ contents: read
+ id-token: write # needed for AWS/ECR login (not used, but required permission)
+ packages: write # needed for GHCR
+
with:
version: ${{ needs.create-release-tag.outputs.version }}
ref: ${{ needs.create-release-tag.outputs.version }}
- secrets:
- SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CLOUD_CI_WEBHOOK_URL }}
- SLACK_MENTION_GROUP_ID: ${{ secrets.SLACK_CORE_SUPPORT_GROUP_ID }}
+ notification-environment: notify-slack-releasing
+ publish-environment: publish-tag
+ secrets: inherit
deploy:
runs-on: ubuntu-24.04
- needs:
- - publish
+ environment: release-deploy
+ needs: [publish]
+ permissions: {}
+
steps:
- name: Get Token
id: get-token
- uses: saleor/saleor-internal-actions/request-vault-token@eb0c692da7bf13f5e1a82c17488b24c514dd10a1 # v1.10.0
+ uses: saleor/saleor-internal-actions/request-vault-token@49a069ae9731cfccf3a1033fe1da4e3da84f4f2a # v1.11.0
with:
vault-url: ${{ secrets.VAULT_URL }}
vault-jwt: ${{ secrets.VAULT_JWT }}
diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml
index e1c14949a6..cb497a3d62 100644
--- a/.github/workflows/e2e.yml
+++ b/.github/workflows/e2e.yml
@@ -15,6 +15,7 @@ on:
- pyproject.toml
- uv.lock
+permissions: {}
env:
DATABASE_URL: "postgres://saleor:saleor@postgres:5432/saleor"
SECRET_KEY: ci-test
@@ -26,6 +27,9 @@ jobs:
container: python:3.12
name: Run E2E tests
+ permissions:
+ contents: read
+
services:
postgres:
image: library/postgres:15-alpine
diff --git a/.github/workflows/github-releases-to-discord.yml b/.github/workflows/github-releases-to-discord.yml
index 6259077e7e..e3420a0901 100644
--- a/.github/workflows/github-releases-to-discord.yml
+++ b/.github/workflows/github-releases-to-discord.yml
@@ -2,9 +2,16 @@ on:
release:
types: [published]
+permissions: {}
+
jobs:
github-releases-to-discord:
runs-on: ubuntu-latest
+ environment: discord-notifier
+
+ permissions:
+ contents: read
+
steps:
- name: Checkout
uses: actions/checkout@v5
diff --git a/.github/workflows/graphql-inspector.yml b/.github/workflows/graphql-inspector.yml
index f4afc4dc00..b307c12bc5 100644
--- a/.github/workflows/graphql-inspector.yml
+++ b/.github/workflows/graphql-inspector.yml
@@ -2,15 +2,21 @@ name: GraphQL Inspector
on:
push:
- paths: [ "**.graphql" ]
+ paths: ["**.graphql"]
+
+permissions: {}
jobs:
build:
runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ checks: write
+
steps:
- uses: actions/checkout@v5
- - uses: graphql-hive/graphql-inspector@release-1769448022768
+ - uses: graphql-hive/graphql-inspector@84c610fac649e0379643da772e77e775c6aeaf56 # release-1769448022768
with:
schema: "main:saleor/graphql/schema.graphql"
diff --git a/.github/workflows/help-wanted-issues-to-discord.yml b/.github/workflows/help-wanted-issues-to-discord.yml
index fe748ec149..02b5afac94 100644
--- a/.github/workflows/help-wanted-issues-to-discord.yml
+++ b/.github/workflows/help-wanted-issues-to-discord.yml
@@ -1,18 +1,28 @@
name: Notify Discord on Help Wanted Issue
on:
+ # We are limiting secrets and not using untrusted inputs for anything
+ # dangerous (e.g., building or executing commands).
+ # nosemgrep: yaml.github-actions.security.audit.dangerous-event-type
issues:
types: [labeled]
+permissions: {}
+
jobs:
notify:
if: github.event.label.name == 'help wanted'
+
+ permissions: {}
+
runs-on: ubuntu-latest
+ environment: discord-notifier
+
steps:
- name: Send notification to Discord
uses: appleboy/discord-action@6047e1fe519c24dbf2865cf0557f20f51f075b3e # v1.2.0
with:
- webhook_url: ${{ secrets.DISCORD_GFI_WEBHOOK_URL }}
+ webhook_url: ${{ secrets.DISCORD_WEBHOOK_URL }}
message: |
🎉 New Issue Labeled with "Help Wanted" in Saleor Core
diff --git a/.github/workflows/migrations-perf-test-check.yml b/.github/workflows/migrations-perf-test-check.yml
index b722f49904..da1fc4e945 100644
--- a/.github/workflows/migrations-perf-test-check.yml
+++ b/.github/workflows/migrations-perf-test-check.yml
@@ -7,6 +7,8 @@ on:
- "**/migrations/**"
types: [labeled, unlabeled, opened, closed]
+permissions: {}
+
jobs:
# Contributors of Saleor sometimes forget about executing migrations performance
# tests on PRs. This job is enforcing decision what to do. The decision is made by
@@ -17,6 +19,8 @@ jobs:
# - migrations perf test - whenever migrations require performance tests
check-migrations-perf-test-decision:
runs-on: ubuntu-latest
+ permissions: {}
+
steps:
- uses: actions/checkout@v5
- name: Check if the decision about migrations perf test was made
diff --git a/.github/workflows/migrations-perf-test.yml b/.github/workflows/migrations-perf-test.yml
index bacebf74e3..b2f1d7a342 100644
--- a/.github/workflows/migrations-perf-test.yml
+++ b/.github/workflows/migrations-perf-test.yml
@@ -9,6 +9,7 @@ jobs:
name: Run migrations performance test
if: ${{ (((github.event.action == 'labeled') && (github.event.label.name == 'migrations perf test')) || ((github.event.action == 'opened') && contains(github.event.pull_request.labels.*.name, 'migrations perf test')) && github.repository == 'saleor/saleor') }}
runs-on: ubuntu-latest
+ environment: migrations-perf-test
permissions:
id-token: write # needed by aws-actions/configure-aws-credentials
contents: read
@@ -16,21 +17,31 @@ jobs:
- uses: actions/checkout@v5
- uses: rlespinasse/github-slug-action@c33ff65466c58d57e4d796f88bb1ae0ff26ee453 # v5.2.0
- - name: Configure AWS Credentials
+ - id: aws-login
+ name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838 # v5.0.0
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_TESTENVS_ACCOUNT_ID }}:role/${{ secrets.AWS_TESTENVS_CICD_ROLE_NAME }}
aws-region: ${{ vars.AWS_TESTENVS_REGION }}
+ # No need to expose the credentials in GITHUB_ENV, instead we only share the
+ # credentials on a need-to-know basis
+ output-env-credentials: "false"
+ output-credentials: "true"
- name: Build and push
uses: kciter/aws-ecr-action@ea6db9ecebec495c996b0f084c8ea1591f1185d7 # v5
with:
- access_key_id: ${{ env.AWS_ACCESS_KEY_ID }}
- secret_access_key: ${{ env.AWS_SECRET_ACCESS_KEY }}
+ access_key_id: ${{ steps.aws-login.outputs.aws-access-key-id }}
+ secret_access_key: ${{ steps.aws-login.outputs.aws-secret-access-key }}
account_id: ${{ secrets.AWS_TESTENVS_ACCOUNT_ID }}
repo: saleor-testenvs
region: ${{ vars.AWS_TESTENVS_REGION }}
tags: ${{ env.GITHUB_HEAD_REF_SLUG_URL }},${{ github.sha }}
+ env:
+ # No input field is present for the session token which thus causes
+ # errors with message: 'The security token included in the request is invalid'
+ # as AWS expects to receive a session token alongside the access key.
+ AWS_SESSION_TOKEN: ${{ steps.aws-login.outputs.aws-session-token }}
- name: Get pull number
run: |
@@ -39,9 +50,9 @@ jobs:
- name: Invoke deployment lambda
uses: gagoar/invoke-aws-lambda@2ea0b5791eba7a9513ddf0fb7f91aa8f098b6458 # v3.4.0
with:
- AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}
- AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }}
- AWS_SESSION_TOKEN: ${{ env.AWS_SESSION_TOKEN }}
+ AWS_ACCESS_KEY_ID: ${{ steps.aws-login.outputs.aws-access-key-id }}
+ AWS_SECRET_ACCESS_KEY: ${{ steps.aws-login.outputs.aws-secret-access-key }}
+ AWS_SESSION_TOKEN: ${{ steps.aws-login.outputs.aws-session-token }}
REGION: ${{ vars.AWS_TESTENVS_REGION }}
FunctionName: migrations-perf-test-manager
Payload: >-
@@ -58,6 +69,7 @@ jobs:
name: Cleanup after migrations performance test
if: ${{ (((github.event.action == 'unlabeled') && (github.event.label.name == 'migrations perf test')) || ((github.event.action == 'closed') && contains(github.event.pull_request.labels.*.name, 'migrations perf test')) && github.repository == 'saleor/saleor') }}
runs-on: ubuntu-latest
+ environment: migrations-perf-test
permissions:
id-token: write # needed by aws-actions/configure-aws-credentials
contents: read
@@ -69,18 +81,23 @@ jobs:
run: |
echo "PULL_ID=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")" >> $GITHUB_ENV
- - name: Configure AWS Credentials
+ - id: aws-login
+ name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838 # v5.0.0
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_TESTENVS_ACCOUNT_ID }}:role/${{ secrets.AWS_TESTENVS_CICD_ROLE_NAME }}
aws-region: ${{ vars.AWS_TESTENVS_REGION }}
+ # No need to expose the credentials in GITHUB_ENV, instead we only share the
+ # credentials on a need-to-know basis
+ output-env-credentials: "false"
+ output-credentials: "true"
- name: Invoke deployment lambda
uses: gagoar/invoke-aws-lambda@2ea0b5791eba7a9513ddf0fb7f91aa8f098b6458 # v3.4.0
with:
- AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}
- AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }}
- AWS_SESSION_TOKEN: ${{ env.AWS_SESSION_TOKEN }}
+ AWS_ACCESS_KEY_ID: ${{ steps.aws-login.outputs.aws-access-key-id }}
+ AWS_SECRET_ACCESS_KEY: ${{ steps.aws-login.outputs.aws-secret-access-key }}
+ AWS_SESSION_TOKEN: ${{ steps.aws-login.outputs.aws-session-token }}
REGION: ${{ vars.AWS_TESTENVS_REGION }}
FunctionName: migrations-perf-test-manager
Payload: >-
diff --git a/.github/workflows/publish-containers.yml b/.github/workflows/publish-containers.yml
index 8dd2ba3145..f19ba3ca2c 100644
--- a/.github/workflows/publish-containers.yml
+++ b/.github/workflows/publish-containers.yml
@@ -15,6 +15,14 @@ on:
description: Optional custom image version tag
required: false
type: string
+ publish-environment:
+ description: GitHub Environment name used for OIDC and secrets for build-push phase.
+ required: true
+ type: string
+ notification-environment:
+ description: The secrets for sending Slack notifications about the release.
+ required: true
+ type: string
secrets:
SLACK_WEBHOOK_URL:
SLACK_MENTION_GROUP_ID:
@@ -23,6 +31,8 @@ on:
description: Docker image version
value: ${{ jobs.prepare-variables.outputs.version }}
+permissions: {}
+
jobs:
prepare-variables:
name: Prepare variables
@@ -80,7 +90,7 @@ jobs:
- name: Docker metadata
id: metadata
- uses: docker/metadata-action@v5
+ uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
with:
images: |
ghcr.io/${{ steps.get-image-name.outputs.image_name }}
@@ -94,16 +104,16 @@ jobs:
type=raw,value=latest,enable=${{ steps.check-latest.outputs.IS_LATEST }}
context: git
-
build-push:
needs: prepare-variables
- uses: saleor/saleor-internal-actions/.github/workflows/build-push-image-multi-platform.yaml@92c29aa0e4545de579b892b2ef9f2d6366c29c11 # v1.5.2
+ uses: saleor/saleor-internal-actions/.github/workflows/build-push-image-multi-platform.yaml@49a069ae9731cfccf3a1033fe1da4e3da84f4f2a # v1.11.0
permissions:
contents: read
id-token: write # needed for AWS/ECR login (not used, but required permission)
packages: write # needed for GHCR
with:
checkout-ref: ${{ inputs.ref }}
+ publish-environment: ${{ inputs.publish-environment }}
enable-ghcr: true
oci-full-repository: ghcr.io/${{ needs.prepare-variables.outputs.image_name }}
@@ -116,11 +126,13 @@ jobs:
notify:
if: ${{ failure() }}
needs: [prepare-variables, build-push]
- uses: saleor/saleor-internal-actions/.github/workflows/notify-slack.yaml@eb0c692da7bf13f5e1a82c17488b24c514dd10a1 # v1.10.0
+ uses: saleor/saleor-internal-actions/.github/workflows/notify-slack.yaml@49a069ae9731cfccf3a1033fe1da4e3da84f4f2a # v1.11.0
with:
type: build
ref: ${{ needs.prepare-variables.outputs.version || inputs.ref || github.ref_name }}
status: failure
- secrets:
- slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
- mention_group_id: ${{ secrets.SLACK_MENTION_GROUP_ID }}
+ github-environment: ${{ inputs.notification-environment }}
+ # Secrets used:
+ # - SLACK_WEBHOOK_URL
+ # - MENTION_GROUP_ID
+ secrets: inherit # needed due to using environments
diff --git a/.github/workflows/publish-load-test.yml b/.github/workflows/publish-load-test.yml
index 054e144b22..1a8ebdc8d7 100644
--- a/.github/workflows/publish-load-test.yml
+++ b/.github/workflows/publish-load-test.yml
@@ -5,43 +5,55 @@ on:
types: [reopened, synchronize, labeled]
branches: ["**"]
+permissions: {}
+
jobs:
init:
if: ${{ ((github.event.action == 'labeled') && (github.event.label.name == 'load test')) || ((github.event.action != 'labeled') && contains(github.event.pull_request.labels.*.name, 'load test')) }}
runs-on: ubuntu-latest
+ permissions: {}
+
outputs:
version: ${{ steps.variables.outputs.version }}
+
steps:
- name: Prepare variables
id: variables
- run:
- set -x
-
- branch=${{ github.event.pull_request.head.ref }}
- branch_slug=$(echo "$branch" | sed 's@/@-@g')
- branch_sha=${{ github.event.pull_request.head.sha }}
- image_version="${branch_slug}-${branch_sha:0:8}"
+ env:
+ HEAD_REF: ${{ github.event.pull_request.head.ref }}
+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}
+ run: |
+ branch_slug=$(echo "$HEAD_REF" | sed 's@/@-@g')
+ image_version="${branch_slug}-${HEAD_SHA:0:8}"
echo "VERSION=${image_version}" >> $GITHUB_OUTPUT
publish:
- needs:
- - init
+ needs: [init]
+ permissions:
+ contents: read
+ id-token: write # needed for AWS/ECR login (not used, but required permission)
+ packages: write # needed for GHCR
+
uses: ./.github/workflows/publish-containers.yml
with:
version: ${{ needs.init.outputs.version }}
- secrets:
- SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CLOUD_CI_WEBHOOK_URL }}
- SLACK_MENTION_GROUP_ID: ${{ secrets.SLACK_CORE_SUPPORT_GROUP_ID }}
+ notification-environment: notify-slack-releasing
+ publish-environment: publish-load-test
+ secrets: inherit
deploy:
runs-on: ubuntu-latest
+ environment: load-test-deploy
+ permissions: {}
+
needs:
- publish
+
steps:
- name: Get Token
id: get-token
- uses: saleor/saleor-internal-actions/request-vault-token@eb0c692da7bf13f5e1a82c17488b24c514dd10a1 # v1.10.0
+ uses: saleor/saleor-internal-actions/request-vault-token@49a069ae9731cfccf3a1033fe1da4e3da84f4f2a # v1.11.0
with:
vault-url: ${{ secrets.VAULT_URL }}
vault-jwt: ${{ secrets.VAULT_JWT }}
diff --git a/.github/workflows/publish-main.yml b/.github/workflows/publish-main.yml
index 81b02639d2..97b73a7613 100644
--- a/.github/workflows/publish-main.yml
+++ b/.github/workflows/publish-main.yml
@@ -6,11 +6,19 @@ on:
- main
- ci/**
+permissions: {}
+
jobs:
publish:
uses: ./.github/workflows/publish-containers.yml
+
+ permissions:
+ contents: read
+ id-token: write # needed for AWS/ECR login (not used, but required permission)
+ packages: write # needed for GHCR
+
with:
prefix: unstable-
- secrets:
- SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CLOUD_CI_WEBHOOK_URL }}
- SLACK_MENTION_GROUP_ID: ${{ secrets.SLACK_CORE_SUPPORT_GROUP_ID }}
+ notification-environment: notify-slack-releasing
+ publish-environment: publish-main
+ secrets: inherit
diff --git a/.github/workflows/test-env-cleanup-cron.yml b/.github/workflows/test-env-cleanup-cron.yml
index ae1ea8b160..678d53c129 100644
--- a/.github/workflows/test-env-cleanup-cron.yml
+++ b/.github/workflows/test-env-cleanup-cron.yml
@@ -3,7 +3,7 @@ name: TEST-ENV-CLEANUP-CRON
on:
schedule:
- - cron: '0 2 * * *' # UTC
+ - cron: "0 2 * * *" # UTC
workflow_dispatch:
jobs:
@@ -11,16 +11,13 @@ jobs:
if: ${{ github.event_name != 'schedule' || github.repository == 'saleor/saleor' }}
name: Remove stale test env deployments
runs-on: ubuntu-latest
+ environment: testenvs-cleanup
+
permissions:
id-token: write # needed by aws-actions/configure-aws-credentials
contents: read
- steps:
- - name: Configure AWS Credentials
- uses: aws-actions/configure-aws-credentials@00943011d9042930efac3dcd3a170e4273319bc8 # v5.1.0
- with:
- role-to-assume: arn:aws:iam::${{ secrets.AWS_TESTENVS_ACCOUNT_ID }}:role/${{ secrets.AWS_TESTENVS_CICD_ROLE_NAME }}
- aws-region: ${{ vars.AWS_TESTENVS_REGION }}
+ steps:
- name: Get branches from open PRs with "test deployment" label and slugify
id: get-branches-and-slugify
uses: actions/github-script@v8
@@ -47,13 +44,24 @@ jobs:
.replace(/-+$/, '') // remove trailing -
);
+ - name: Configure AWS Credentials
+ uses: aws-actions/configure-aws-credentials@00943011d9042930efac3dcd3a170e4273319bc8 # v5.1.0
+ id: aws-login
+ with:
+ role-to-assume: arn:aws:iam::${{ secrets.AWS_TESTENVS_ACCOUNT_ID }}:role/${{ secrets.AWS_TESTENVS_CICD_ROLE_NAME }}
+ aws-region: ${{ vars.AWS_TESTENVS_REGION }}
+ # No need to expose the credentials in GITHUB_ENV, instead we only share the
+ # credentials on a need-to-know basis
+ output-env-credentials: "false"
+ output-credentials: "true"
+
- name: Invoke test-env-manager lambda
id: lambda
uses: gagoar/invoke-aws-lambda@2ea0b5791eba7a9513ddf0fb7f91aa8f098b6458 # v3.4.0
with:
- AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}
- AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }}
- AWS_SESSION_TOKEN: ${{ env.AWS_SESSION_TOKEN }}
+ AWS_ACCESS_KEY_ID: ${{ steps.aws-login.outputs.aws-access-key-id }}
+ AWS_SECRET_ACCESS_KEY: ${{ steps.aws-login.outputs.aws-secret-access-key }}
+ AWS_SESSION_TOKEN: ${{ steps.aws-login.outputs.aws-session-token }}
REGION: ${{ vars.AWS_TESTENVS_REGION }}
FunctionName: test-env-manager
Payload: >-
diff --git a/.github/workflows/test-env-cleanup.yml b/.github/workflows/test-env-cleanup.yml
index 60d35c0d54..4cee63d73f 100644
--- a/.github/workflows/test-env-cleanup.yml
+++ b/.github/workflows/test-env-cleanup.yml
@@ -6,15 +6,22 @@ on:
types: [closed, unlabeled]
branches: ["**"]
+permissions: {}
+
jobs:
- cleanup:
+ cleanup-aws:
name: Remove test environment deployment
if: ${{ ((github.event.action == 'unlabeled') && (github.event.label.name == 'test deployment')) || ((github.event.action == 'closed') && contains(github.event.pull_request.labels.*.name, 'test deployment')) }}
runs-on: ubuntu-latest
+ environment: testenvs-cleanup
+
permissions:
id-token: write # needed by aws-actions/configure-aws-credentials
contents: read
- deployments: write
+
+ outputs:
+ slug: ${{ steps.slugify-branch-name.outputs.result }}
+
steps:
- name: Generate GITHUB_HEAD_REF_SLUG_URL
id: slugify-branch-name
@@ -32,19 +39,24 @@ jobs:
.slice(0, 63) // trim length down (limit is up to 64 characters)
.replace(/-+$/, ''); // remove trailing dash
- - name: Configure AWS Credentials
+ - id: aws-login
+ name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838 # v5.0.0
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_TESTENVS_ACCOUNT_ID }}:role/${{ secrets.AWS_TESTENVS_CICD_ROLE_NAME }}
aws-region: ${{ vars.AWS_TESTENVS_REGION }}
+ # No need to expose the credentials in GITHUB_ENV, instead we only share the
+ # credentials on a need-to-know basis
+ output-env-credentials: "false"
+ output-credentials: "true"
- name: Invoke deployment lambda
id: lambda
uses: gagoar/invoke-aws-lambda@2ea0b5791eba7a9513ddf0fb7f91aa8f098b6458 # v3.4.0
with:
- AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}
- AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }}
- AWS_SESSION_TOKEN: ${{ env.AWS_SESSION_TOKEN }}
+ AWS_ACCESS_KEY_ID: ${{ steps.aws-login.outputs.aws-access-key-id }}
+ AWS_SECRET_ACCESS_KEY: ${{ steps.aws-login.outputs.aws-secret-access-key }}
+ AWS_SESSION_TOKEN: ${{ steps.aws-login.outputs.aws-session-token }}
REGION: ${{ vars.AWS_TESTENVS_REGION }}
FunctionName: test-env-manager
Payload: >-
@@ -86,9 +98,19 @@ jobs:
echo "${PAYLOAD:-null}"
echo "--------"
+ cleanup-github:
+ name: Update GitHub Deployment Status
+ runs-on: ubuntu-latest
+
+ permissions:
+ deployments: write
+
+ needs: [cleanup-aws]
+
+ steps:
- name: Mark deployment as deactivated
uses: bobheadxi/deployments@648679e8e4915b27893bd7dbc35cb504dc915bc8 # v1.5.0
with:
step: deactivate-env
token: ${{ secrets.GITHUB_TOKEN }}
- env: ${{ steps.slugify-branch-name.outputs.result }}
+ env: ${{ needs.cleanup-aws.outputs.slug }}
diff --git a/.github/workflows/test-env-deploy.yml b/.github/workflows/test-env-deploy.yml
index 295114c276..32062a8032 100644
--- a/.github/workflows/test-env-deploy.yml
+++ b/.github/workflows/test-env-deploy.yml
@@ -6,18 +6,23 @@ on:
types: [reopened, synchronize, labeled]
branches: ["**"]
+permissions: {}
+
jobs:
- deploy:
+ prepare:
name: Deploy test environment for labeled pull requests
if: ${{ ((github.event.action == 'labeled') && (github.event.label.name == 'test deployment')) || ((github.event.action != 'labeled') && contains(github.event.pull_request.labels.*.name, 'test deployment')) }}
runs-on: ubuntu-latest
+
permissions:
- id-token: write # needed by aws-actions/configure-aws-credentials
- contents: read
deployments: write
- steps:
- - uses: actions/checkout@v6
+ outputs:
+ slug: ${{ steps.slugify-branch-name.outputs.result }}
+ domain: ${{ steps.set-domain.outputs.domain }}
+ github-deployment-id: ${{ steps.deployment.outputs.deployment_id }}
+
+ steps:
- name: Generate GITHUB_HEAD_REF_SLUG_URL
id: slugify-branch-name
uses: actions/github-script@v8
@@ -36,9 +41,11 @@ jobs:
- name: Set domain
id: set-domain
+ env:
+ ENV_SLUG: ${{ steps.slugify-branch-name.outputs.result }}
# Set test instance domain based on branch name slug
run: |
- echo "domain=${{ steps.slugify-branch-name.outputs.result }}.api.saleor.rocks" >> $GITHUB_OUTPUT
+ echo "domain=${ENV_SLUG}.api.saleor.rocks" >> $GITHUB_OUTPUT
- name: Start deployment
uses: bobheadxi/deployments@648679e8e4915b27893bd7dbc35cb504dc915bc8 # v1.5.0
@@ -49,35 +56,59 @@ jobs:
env: ${{ steps.slugify-branch-name.outputs.result }}
ref: ${{ github.head_ref }}
- - name: Configure AWS Credentials
+ build-deploy:
+ name: Build & Deploy
+ needs: [prepare]
+ runs-on: ubuntu-latest
+
+ environment: testenvs-deploy
+
+ permissions:
+ contents: read
+ id-token: write # needed by aws-actions/configure-aws-credentials
+
+ steps:
+ - uses: actions/checkout@v6
+
+ - id: aws-login
+ name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708 # v5.1.1
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_TESTENVS_ACCOUNT_ID }}:role/${{ secrets.AWS_TESTENVS_CICD_ROLE_NAME }}
aws-region: ${{ vars.AWS_TESTENVS_REGION }}
+ # No need to expose the credentials in GITHUB_ENV, instead we only share the
+ # credentials on a need-to-know basis
+ output-env-credentials: "false"
+ output-credentials: "true"
- name: Build and push
uses: kciter/aws-ecr-action@ea6db9ecebec495c996b0f084c8ea1591f1185d7 # v5
with:
- access_key_id: ${{ env.AWS_ACCESS_KEY_ID }}
- secret_access_key: ${{ env.AWS_SECRET_ACCESS_KEY }}
+ access_key_id: ${{ steps.aws-login.outputs.aws-access-key-id }}
+ secret_access_key: ${{ steps.aws-login.outputs.aws-secret-access-key }}
account_id: ${{ secrets.AWS_TESTENVS_ACCOUNT_ID }}
repo: saleor-testenvs
region: ${{ vars.AWS_TESTENVS_REGION }}
- tags: ${{ steps.slugify-branch-name.outputs.result }},${{ github.sha }}
+ tags: ${{ needs.prepare.outputs.slug }},${{ github.sha }}
+ env:
+ # No input field is present for the session token which thus causes
+ # errors with message: 'The security token included in the request is invalid'
+ # as AWS expects to receive a session token alongside the access key.
+ AWS_SESSION_TOKEN: ${{ steps.aws-login.outputs.aws-session-token }}
- name: Invoke deployment lambda
id: lambda
uses: gagoar/invoke-aws-lambda@2ea0b5791eba7a9513ddf0fb7f91aa8f098b6458 # v3.4.0
with:
- AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}
- AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }}
- AWS_SESSION_TOKEN: ${{ env.AWS_SESSION_TOKEN }}
+ AWS_ACCESS_KEY_ID: ${{ steps.aws-login.outputs.aws-access-key-id }}
+ AWS_SECRET_ACCESS_KEY: ${{ steps.aws-login.outputs.aws-secret-access-key }}
+ AWS_SESSION_TOKEN: ${{ steps.aws-login.outputs.aws-session-token }}
REGION: ${{ vars.AWS_TESTENVS_REGION }}
FunctionName: test-env-manager
Payload: >-
{
"action": "${{ github.event.action }}",
- "label": "${{ steps.slugify-branch-name.outputs.result }}",
+ "label": "${{ needs.prepare.outputs.slug }}",
"image": "${{ secrets.AWS_TESTENVS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_TESTENVS_REGION }}.amazonaws.com/saleor-testenvs:${{ github.sha }}"
}
LogType: Tail
@@ -113,13 +144,22 @@ jobs:
echo "${PAYLOAD:-null}"
echo "--------"
+ complete:
+ # Doesn't match when job is skipped
+ if: ${{ success() || failure() || cancelled() }}
+ runs-on: ubuntu-latest
+ needs: [prepare, build-deploy]
+
+ permissions:
+ deployments: write
+
+ steps:
- name: Update deployment status
uses: bobheadxi/deployments@648679e8e4915b27893bd7dbc35cb504dc915bc8 # v1.5.0
- if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
- env: ${{ steps.slugify-branch-name.outputs.result }}
+ env: ${{ needs.prepare.outputs.slug }}
status: ${{ job.status }}
- env_url: https://${{ steps.set-domain.outputs.domain }}/graphql/
- deployment_id: ${{ steps.deployment.outputs.deployment_id }}
+ env_url: https://${{ needs.prepare.outputs.domain }}/graphql/
+ deployment_id: ${{ needs.prepare.outputs.github-deployment-id }}
diff --git a/.github/workflows/test-migrations-compatibility.yml b/.github/workflows/test-migrations-compatibility.yml
index 6fc8e2a264..df01da7c73 100644
--- a/.github/workflows/test-migrations-compatibility.yml
+++ b/.github/workflows/test-migrations-compatibility.yml
@@ -13,11 +13,16 @@ env:
DATABASE_URL: "postgres://saleor:saleor@postgres:5432/saleor"
SECRET_KEY: ci-test
+permissions: {}
+
jobs:
build:
runs-on: ubuntu-latest
container: python:3.12
+ permissions:
+ contents: read
+
services:
postgres:
image: library/postgres:15-alpine
@@ -54,7 +59,7 @@ jobs:
- name: Checkout base
uses: actions/checkout@v5
with:
- ref: ${{ github['base_ref'] }}
+ ref: ${{ github.event.pull_request.base.sha }}
# Sync dependencies to ensure consistency with base branch
- name: Synchronize dependencies
@@ -63,5 +68,5 @@ jobs:
- name: Run tests
run: |
- export PYTEST_DB_URL=$DATABASE_URL
+ export PYTEST_DB_URL="$DATABASE_URL"
uv run pytest -n 0 --reuse-db
diff --git a/.github/workflows/test-semgrep-rules.yml b/.github/workflows/test-semgrep-rules.yml
index e0840cc5d7..3d6560c34e 100644
--- a/.github/workflows/test-semgrep-rules.yml
+++ b/.github/workflows/test-semgrep-rules.yml
@@ -11,11 +11,16 @@ on:
- .github/workflows/test-semgrep-rules.yml
- .pre-commit-config.yaml
+permissions: {}
+
jobs:
main:
runs-on: ubuntu-22.04
container: python:3.12-slim
+ permissions:
+ contents: read
+
steps:
- name: Checkout
uses: actions/checkout@v5
diff --git a/.github/workflows/tests-and-linters.yml b/.github/workflows/tests-and-linters.yml
index 0101625501..3916bfe638 100644
--- a/.github/workflows/tests-and-linters.yml
+++ b/.github/workflows/tests-and-linters.yml
@@ -2,7 +2,7 @@ name: Tests & Linters
on:
pull_request:
- types: [ opened, synchronize, reopened ]
+ types: [opened, synchronize, reopened]
paths:
- "**.py"
- Dockerfile
@@ -13,7 +13,6 @@ on:
push:
branches:
- main
- - ci/*
paths:
- "**.py"
- Dockerfile
@@ -34,12 +33,17 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
+permissions: {}
+
jobs:
unit_tests:
runs-on: ubuntu-latest
container: python:3.12
name: Run unit tests
+ permissions:
+ contents: read
+
services:
postgres:
image: library/postgres:15-alpine
@@ -75,56 +79,72 @@ jobs:
uv sync --locked
- name: Run unit tests
- env:
- COVERAGE_CORE: sysmon
run: |
uv run pytest \
-m "not e2e" \
- --cov \
- --cov-report= \
--junitxml=junit/test-results.xml \
-o junit_family=legacy \
- --django-db-bench=${{ env.BENCH_PATH }} \
+ --django-db-bench="$BENCH_PATH" \
-n logical
- - name: Upload test results to Codecov
- if: ${{ !cancelled() }} # Run even if tests fail
- uses: codecov/test-results-action@v1
- with:
- token: ${{ secrets.CODECOV_TOKEN }}
-
- # Publish coverage and test results
- - uses: codecov/codecov-action@v5
- env:
- CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
-
- - uses: actions/upload-artifact@v4
+ - name: Upload Test Results
+ uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: pytest-results
path: junit/test-results.xml
+ # Throw an error if test results aren't reported. This could happen
+ # when bumping dependencies for example.
+ if-no-files-found: error
if: ${{ always() }}
# Publish detected differences as comment
- - uses: NyanKiyoshi/pytest-django-queries-ci-tools@v1
+ - name: Compare DB Queries Results (PR)
+ uses: NyanKiyoshi/pytest-django-queries-ci-tools@45b5ac36ff19669a88fe56429b662b0661d8f46b # v1.1.1
with:
query_raw_dump_path: ${{ env.BENCH_PATH }}
diff_endpoint: "https://dtab784j47g1o.cloudfront.net/default/saleor-db-queries-bot-diff"
diff_results_base_url: "https://dtab784j47g1o.cloudfront.net"
if: github.event_name == 'pull_request' && github.repository == 'saleor/saleor'
- # Save results for future comparison against pull requests
- - uses: NyanKiyoshi/pytest-django-queries-ci-tools@v1
+ - name: Upload DB Queries Results
+ uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
- query_raw_dump_path: ${{ env.BENCH_PATH }}
+ name: pytest-django-db-queries-results
+ path: ${{ env.BENCH_PATH }}
+ if-no-files-found: error
+
+ # Uploads the SQL count report for base branches
+ upload-query-count-base-branch:
+ if: github.event_name == 'push' && github.repository == 'saleor/saleor'
+
+ needs: [unit_tests]
+ runs-on: ubuntu-latest
+ environment: pytest-upload-django-db-queries
+
+ permissions: {}
+
+ steps:
+ - name: Download Reports
+ uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
+ with:
+ name: pytest-django-db-queries-results
+ path: results/
+
+ - name: Upload Results
+ uses: NyanKiyoshi/pytest-django-queries-ci-tools@45b5ac36ff19669a88fe56429b662b0661d8f46b # v1.1.1
+ with:
+ query_raw_dump_path: results/queries-results.json
upload_endpoint: ${{ secrets.QUERIES_UPLOAD_ENDPOINT_URL }}
upload_secret_key: ${{ secrets.QUERIES_UPLOAD_SECRET }}
- if: github.event_name == 'push' && github.repository == 'saleor/saleor'
linters:
runs-on: ubuntu-latest
container: python:3.12
name: Run linters
+ permissions:
+ contents: read
+
steps:
- uses: actions/checkout@v5