Skip to content

Commit 44e7a89

Browse files
committed
ci: adjust “Diff & Comment” for the current deployment code
LW-9879
1 parent e8cbce5 commit 44e7a89

File tree

1 file changed

+51
-33
lines changed

1 file changed

+51
-33
lines changed

.github/workflows/std.yml

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,9 @@ on:
2020
tags:
2121
- '@cardano-sdk/cardano-services**'
2222
env:
23-
AWS_REGION: us-east-1
24-
AWS_ROLE_ARN: arn:aws:iam::926093910549:role/lace-ci
2523
# NIX_UPLOAD_CACHE: s3://lace-nix-cache?region=us-east-1
2624
DISCOVERY_USER_NAME: gha-runner
2725
DISCOVERY_KNOWN_HOSTS_ENTRY: "65.109.126.156 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEOVVDZydvD+diYa6A3EtA3WGw5NfN0wv7ckQxa/fX1O"
28-
permissions:
29-
id-token: write
30-
contents: read
3126
concurrency:
3227
group: std-${{ github.workflow }}-${{ github.ref }}
3328
cancel-in-progress: true
@@ -36,6 +31,12 @@ jobs:
3631
outputs:
3732
hits: ${{ steps.discovery.outputs.hits }}
3833
runs-on: [self-hosted, discovery]
34+
env:
35+
AWS_REGION: us-east-1
36+
AWS_ROLE_ARN: arn:aws:iam::926093910549:role/lace-ci
37+
permissions:
38+
id-token: write
39+
contents: read
3940
steps:
4041
- name: Configure AWS Credentials
4142
uses: aws-actions/[email protected]
@@ -67,6 +68,13 @@ jobs:
6768
name: ${{ matrix.target.jobName }}
6869
runs-on: ubuntu-latest
6970
needs: discover
71+
env:
72+
AWS_REGION: us-east-1
73+
AWS_ROLE_ARN: arn:aws:iam::926093910549:role/lace-ci
74+
# NIX_UPLOAD_CACHE: s3://lace-nix-cache?region=us-east-1
75+
permissions:
76+
id-token: write
77+
contents: read
7078
strategy:
7179
matrix:
7280
target: ${{ contains(fromJSON(needs.discover.outputs.hits), 'oci-images') && fromJSON(needs.discover.outputs.hits).oci-images.publish || fromJSON('["dummy-target"]') }}
@@ -103,51 +111,61 @@ jobs:
103111
with: {ffBuildInstructions: true, remoteStore: "ssh-ng://eu.nixbuild.net"}
104112

105113

106-
diff-to-eu:
107-
runs-on: ubuntu-latest
108-
needs: [discover, images]
109-
name: ${{ matrix.target.jobName }} (us-east-1)
110-
env:
111-
AWS_REGION: us-east-1
114+
# TODO: remove all hardcoded instances of `dev-preview` in the next iteration
115+
diff-to-us:
116+
needs: images
117+
name: Diff & Comment (dev-preview)
118+
if: github.event_name == 'pull_request' && (github.base_ref == 'master')
112119
permissions:
113-
id-token: write
114120
contents: read
115121
pull-requests: write
116-
if: fromJSON(needs.discover.outputs.hits).deployments.diff != '{}' && github.event_name == 'pull_request'
117-
strategy:
118-
matrix:
119-
target: ${{ fromJSON(needs.discover.outputs.hits).deployments.diff }}
122+
runs-on: ubuntu-22.04
120123
steps:
121-
- name: Configure AWS Credentials
122-
uses: aws-actions/[email protected]
123-
with:
124-
role-to-assume: ${{ env.AWS_ROLE_ARN }}
125-
aws-region: ${{ env.AWS_REGION }}
124+
- uses: actions/checkout@v4
126125
- uses: nixbuild/nix-quick-install-action@v25
127126
- uses: nixbuild/nixbuild-action@v17
128127
with:
129128
nixbuild_ssh_key: ${{ secrets.SSH_PRIVATE_KEY }}
130129
generate_summary_for: job
130+
# Further steps assume AWS_PROFILE=lw, while the official action has no way to specify that profile:
131+
- name: Set up AWS credentials
132+
run: |
133+
mkdir -p ~/.aws
134+
135+
cat <<EOF >~/.aws/credentials
136+
[lw]
137+
aws_access_key_id = ${{ secrets.AWS_ACCESS_KEY}}
138+
aws_secret_access_key = ${{ secrets.AWS_SECRET_ACCESS_KEY }}
139+
EOF
140+
141+
cat <<EOF >~/.aws/config
142+
[lw]
143+
region = us-east-1
144+
EOF
131145
- uses: divnix/std-action/setup-discovery-ssh@main
132146
with:
133147
ssh_key: ${{ secrets.SSH_PRIVATE_KEY }}
134148
user_name: ${{ env.DISCOVERY_USER_NAME }}
135149
ssh_known_hosts_entry: ${{ env.DISCOVERY_KNOWN_HOSTS_ENTRY }}
136-
- name: Configure K8S Cluster Access
137-
shell: bash
138-
run: |
139-
echo "Assuming role '$(aws sts get-caller-identity)' in cluster 'lace-dev-us-east-1'."
140-
aws eks update-kubeconfig --name "lace-dev-us-east-1"
141-
- name: Show commit
142-
shell: bash
150+
- name: Generate the Diff
143151
run: |
144-
echo commit: ${{ github.sha }}
145-
- uses: divnix/std-action/run@main
152+
echo 'export K8S_USER=eks-devs' >.envrc.local
153+
154+
nix develop .#x86_64-linux.local.envs.main -L --command bash -c '
155+
set -euo pipefail
156+
157+
export AWS_PROFILE="lw"
158+
export AWS_REGION="us-east-1"
159+
160+
# FIXME: before merging: change target to `dev-preview@us-east-1`
161+
nix run -L ".#[email protected]" | tee k8s-plan.diff
162+
'
163+
- name: Post Comment on the PR
146164
env:
147-
BRANCH: ${{ github.ref_type == 'branch' && github.head_ref }}
148165
GH_TOKEN: ${{ github.token }}
149-
OWNER_AND_REPO: ${{ github.repository }}
150-
with: {ffBuildInstructions: true, remoteStore: "ssh-ng://eu.nixbuild.net"}
166+
run: |
167+
prNumber=$(cut -d/ -f1 <<<'${{ github.ref_name }}')
168+
gh pr comment "$prNumber" --body "$(sed -e '2i\\n```diff' -e '$a```' k8s-plan.diff)"
151169
152170
153171
deploy-to-eu:

0 commit comments

Comments
 (0)