Skip to content

Commit edca86c

Browse files
committed
Adjust reusable workflows for custom tree_hash
1 parent 4434fd0 commit edca86c

File tree

2 files changed

+39
-25
lines changed

2 files changed

+39
-25
lines changed

.github/workflows/deploy.yml

+19-12
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ on:
2222
default: "dist"
2323
description: "Directory where the bundle should be unpacked"
2424
type: string
25-
tree_hash:
25+
deploy_hash:
2626
required: true
2727
description: "Tree hash of the code to deploy"
2828
type: string
@@ -75,12 +75,12 @@ jobs:
7575
- name: Check version already deployed
7676
id: is-version-already-deployed
7777
run: |
78-
DEPLOY_EXISTS=$(aws s3 ls s3://${{ inputs.bucket_name }}/html/${{ inputs.tree_hash }}/ || true)
78+
DEPLOY_EXISTS=$(aws s3 ls s3://${{ inputs.bucket_name }}/html/${{ inputs.deploy_hash }}/ || true)
7979
if [ -z "$DEPLOY_EXISTS" ]; then
80-
echo "Version ${{ inputs.tree_hash }} not yet deployed"
80+
echo "Version ${{ inputs.deploy_hash }} not yet deployed"
8181
echo "is_deployed=false" >> $GITHUB_OUTPUT
8282
else
83-
echo "Version ${{ inputs.tree_hash }} already deployed"
83+
echo "Version ${{ inputs.deploy_hash }} already deployed"
8484
echo "is_deployed=true" >> $GITHUB_OUTPUT
8585
fi
8686
@@ -94,7 +94,7 @@ jobs:
9494
echo "Could not determine default branch"
9595
exit 1
9696
fi
97-
SUBDOMAIN=$([[ $GITHUB_REF = "refs/heads/$DEFAULT_BRANCH" || $GITHUB_REF = "refs/heads/change-freeze-emergency-deploy" ]] && echo "" || echo "preview-${{ inputs.tree_hash }}.")
97+
SUBDOMAIN=$([[ $GITHUB_REF = "refs/heads/$DEFAULT_BRANCH" || $GITHUB_REF = "refs/heads/change-freeze-emergency-deploy" ]] && echo "" || echo "preview-${{ inputs.deploy_hash }}.")
9898
echo "url=https://${SUBDOMAIN}${{ inputs.domain_name }}" >> $GITHUB_OUTPUT
9999
100100
- name: Setup AWS Credentials for Registry Bucket Access
@@ -124,7 +124,7 @@ jobs:
124124
NODE_AUTH_TOKEN: ${{ secrets.GH_REGISTRY_NPM_TOKEN }}
125125
SPA_BUNDLE_DIR: ${{ inputs.bundle_dir }}
126126
SPA_ENV: ${{inputs.environment}}
127-
SPA_TREE_HASH: ${{ inputs.tree_hash}}
127+
SPA_TREE_HASH: ${{ inputs.deploy_hash}}
128128
run: ${{inputs.inject_config_cmd }}
129129

130130
- name: Copy Static Files
@@ -137,7 +137,7 @@ jobs:
137137
- name: Copy HTML Files
138138
if: ${{ steps.is-version-already-deployed.outputs.is_deployed == 'false'}}
139139
run: |
140-
aws s3 cp ${{ inputs.bundle_dir }}/ s3://${{ inputs.bucket_name }}/html/${{ inputs.tree_hash }} \
140+
aws s3 cp ${{ inputs.bundle_dir }}/ s3://${{ inputs.bucket_name }}/html/${{ inputs.deploy_hash }} \
141141
--cache-control 'public,max-age=31536000,immutable' \
142142
--recursive \
143143
--exclude "static/*"
@@ -146,18 +146,25 @@ jobs:
146146
if: ${{ steps.is-version-already-deployed.outputs.is_deployed == 'false'}}
147147
run: |
148148
aws s3 cp \
149-
s3://${{ inputs.bucket_name }}/html/${{ inputs.tree_hash }}/.well-known/apple-app-site-association \
150-
s3://${{ inputs.bucket_name }}/html/${{ inputs.tree_hash }}/.well-known/apple-app-site-association \
149+
s3://${{ inputs.bucket_name }}/html/${{ inputs.deploy_hash }}/.well-known/apple-app-site-association \
150+
s3://${{ inputs.bucket_name }}/html/${{ inputs.deploy_hash }}/.well-known/apple-app-site-association \
151151
--content-type 'application/json' \
152152
--cache-control 'public,max-age=3600' \
153153
--metadata-directive REPLACE || echo "Failed updating .well-known files"
154154
155+
# We always copy deploy hash file even if we don't do an actual deployemnt as part of this commit
156+
# This is used to identify which version of the deployed app is associated with the current commit
157+
# In case we trigger rollback to this commit, we know what deployment to use based on the stored deploy_hash for this commit
158+
- name: Copy Deploy Hash File
159+
run: |
160+
echo ${{ inputs.deploy_hash }} >> ${{ github.sha }}
161+
aws s3 cp ${{ github.sha }} s3://${{ inputs.bucket_name }}/deploys/commits/${{ github.sha }}
162+
155163
- name: Update Cursor File
156164
id: cursor-update
157-
uses: pleo-io/spa-tools/actions/cursor-deploy@2af7d6cdcd5fa8b0f2fec3034f6f04afd43ccde5
165+
uses: pleo-io/spa-tools/actions/cursor-deploy@spa-github-actions-v9.0.2
158166
if: ${{ steps.is-version-already-deployed.outputs.is_deployed == 'false'}}
159167
with:
160-
custom_hash: ${{ inputs.tree_hash }}
161168
bucket_name: ${{ inputs.bucket_name }}
162169

163170
- name: Update PR Description
@@ -176,4 +183,4 @@ jobs:
176183
# We expect the injection to insert the version in the HTML.
177184
run:
178185
curl --silent --show-error ${{ steps.deployment-url.outputs.url }} |
179-
grep -q ${{ inputs.tree_hash }}
186+
grep -q ${{ inputs.deploy_hash }}

reusable-workflows/deploy.yml

+20-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ on:
2222
default: "dist"
2323
description: "Directory where the bundle should be unpacked"
2424
type: string
25-
tree_hash:
25+
deploy_hash:
2626
required: true
2727
description: "Tree hash of the code to deploy"
2828
type: string
@@ -75,12 +75,12 @@ jobs:
7575
- name: Check version already deployed
7676
id: is-version-already-deployed
7777
run: |
78-
DEPLOY_EXISTS=$(aws s3 ls s3://${{ inputs.bucket_name }}/html/${{ inputs.tree_hash }}/ || true)
78+
DEPLOY_EXISTS=$(aws s3 ls s3://${{ inputs.bucket_name }}/html/${{ inputs.deploy_hash }}/ || true)
7979
if [ -z "$DEPLOY_EXISTS" ]; then
80-
echo "Version ${{ inputs.tree_hash }} not yet deployed"
80+
echo "Version ${{ inputs.deploy_hash }} not yet deployed"
8181
echo "is_deployed=false" >> $GITHUB_OUTPUT
8282
else
83-
echo "Version ${{ inputs.tree_hash }} already deployed"
83+
echo "Version ${{ inputs.deploy_hash }} already deployed"
8484
echo "is_deployed=true" >> $GITHUB_OUTPUT
8585
fi
8686
@@ -94,7 +94,7 @@ jobs:
9494
echo "Could not determine default branch"
9595
exit 1
9696
fi
97-
SUBDOMAIN=$([[ $GITHUB_REF = "refs/heads/$DEFAULT_BRANCH" || $GITHUB_REF = "refs/heads/change-freeze-emergency-deploy" ]] && echo "" || echo "preview-${{ inputs.tree_hash }}.")
97+
SUBDOMAIN=$([[ $GITHUB_REF = "refs/heads/$DEFAULT_BRANCH" || $GITHUB_REF = "refs/heads/change-freeze-emergency-deploy" ]] && echo "" || echo "preview-${{ inputs.deploy_hash }}.")
9898
echo "url=https://${SUBDOMAIN}${{ inputs.domain_name }}" >> $GITHUB_OUTPUT
9999
100100
- name: Setup AWS Credentials for Registry Bucket Access
@@ -124,7 +124,7 @@ jobs:
124124
NODE_AUTH_TOKEN: ${{ secrets.GH_REGISTRY_NPM_TOKEN }}
125125
SPA_BUNDLE_DIR: ${{ inputs.bundle_dir }}
126126
SPA_ENV: ${{inputs.environment}}
127-
SPA_TREE_HASH: ${{ inputs.tree_hash}}
127+
SPA_TREE_HASH: ${{ inputs.deploy_hash}}
128128
run: ${{inputs.inject_config_cmd }}
129129

130130
- name: Copy Static Files
@@ -137,7 +137,7 @@ jobs:
137137
- name: Copy HTML Files
138138
if: ${{ steps.is-version-already-deployed.outputs.is_deployed == 'false'}}
139139
run: |
140-
aws s3 cp ${{ inputs.bundle_dir }}/ s3://${{ inputs.bucket_name }}/html/${{ inputs.tree_hash }} \
140+
aws s3 cp ${{ inputs.bundle_dir }}/ s3://${{ inputs.bucket_name }}/html/${{ inputs.deploy_hash }} \
141141
--cache-control 'public,max-age=31536000,immutable' \
142142
--recursive \
143143
--exclude "static/*"
@@ -146,22 +146,29 @@ jobs:
146146
if: ${{ steps.is-version-already-deployed.outputs.is_deployed == 'false'}}
147147
run: |
148148
aws s3 cp \
149-
s3://${{ inputs.bucket_name }}/html/${{ inputs.tree_hash }}/.well-known/apple-app-site-association \
150-
s3://${{ inputs.bucket_name }}/html/${{ inputs.tree_hash }}/.well-known/apple-app-site-association \
149+
s3://${{ inputs.bucket_name }}/html/${{ inputs.deploy_hash }}/.well-known/apple-app-site-association \
150+
s3://${{ inputs.bucket_name }}/html/${{ inputs.deploy_hash }}/.well-known/apple-app-site-association \
151151
--content-type 'application/json' \
152152
--cache-control 'public,max-age=3600' \
153153
--metadata-directive REPLACE || echo "Failed updating .well-known files"
154154
155+
# We always copy deploy hash file even if we don't do an actual deployemnt as part of this commit
156+
# This is used to identify which version of the deployed app is associated with the current commit
157+
# In case we trigger rollback to this commit, we know what deployment to use based on the stored deploy_hash for this commit
158+
- name: Copy Deploy Hash File
159+
run: |
160+
echo ${{ inputs.deploy_hash }} >> ${{ github.sha }}
161+
aws s3 cp ${{ github.sha }} s3://${{ inputs.bucket_name }}/deploys/commits/${{ github.sha }}
162+
155163
- name: Update Cursor File
156164
id: cursor-update
157-
uses: pleo-io/spa-tools/actions/cursor-deploy@2af7d6cdcd5fa8b0f2fec3034f6f04afd43ccde5
165+
uses: pleo-io/spa-tools/actions/cursor-deploy@spa-github-actions-v10.0.0
158166
if: ${{ steps.is-version-already-deployed.outputs.is_deployed == 'false'}}
159167
with:
160-
custom_hash: ${{ inputs.tree_hash }}
161168
bucket_name: ${{ inputs.bucket_name }}
162169

163170
- name: Update PR Description
164-
uses: pleo-io/spa-tools/actions/post-preview-urls@spa-github-actions-v9.0.2
171+
uses: pleo-io/spa-tools/actions/post-preview-urls@spa-github-actions-v10.0.0
165172
if: github.event_name == 'pull_request' && ${{ steps.is-version-already-deployed.outputs.is_deployed == 'false'}}
166173
with:
167174
app_name: ${{ inputs.app_name }}
@@ -176,4 +183,4 @@ jobs:
176183
# We expect the injection to insert the version in the HTML.
177184
run:
178185
curl --silent --show-error ${{ steps.deployment-url.outputs.url }} |
179-
grep -q ${{ inputs.tree_hash }}
186+
grep -q ${{ inputs.deploy_hash }}

0 commit comments

Comments
 (0)