22
22
default : " dist"
23
23
description : " Directory where the bundle should be unpacked"
24
24
type : string
25
- tree_hash :
25
+ deploy_hash :
26
26
required : true
27
27
description : " Tree hash of the code to deploy"
28
28
type : string
65
65
registry-url : " https://npm.pkg.github.com"
66
66
scope : ${{ inputs.registry_scope }}
67
67
68
+ - name : Setup AWS Credentials for Origin Bucket Access
69
+ uses :
aws-actions/[email protected]
70
+ with :
71
+ aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
72
+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
73
+ aws-region : eu-west-1
74
+
75
+ - name : Check version already deployed
76
+ id : is-version-already-deployed
77
+ run : |
78
+ DEPLOY_EXISTS=$(aws s3 ls s3://${{ inputs.bucket_name }}/html/${{ inputs.deploy_hash }}/ || true)
79
+ if [ -z "$DEPLOY_EXISTS" ]; then
80
+ echo "Version ${{ inputs.deploy_hash }} not yet deployed"
81
+ echo "is_deployed=false" >> $GITHUB_OUTPUT
82
+ else
83
+ echo "Version ${{ inputs.deploy_hash }} already deployed"
84
+ echo "is_deployed=true" >> $GITHUB_OUTPUT
85
+ fi
86
+
68
87
# For feature preview deployments we're using the permalink as the deploy URL for the GitHub deployment
69
88
# For deployments on the default branch we're using the domain name passed via inputs.
70
89
- name : Get Deployment URL
@@ -75,17 +94,19 @@ jobs:
75
94
echo "Could not determine default branch"
76
95
exit 1
77
96
fi
78
- 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 }}.")
79
98
echo "url=https://${SUBDOMAIN}${{ inputs.domain_name }}" >> $GITHUB_OUTPUT
80
99
81
100
- name : Setup AWS Credentials for Registry Bucket Access
82
101
uses :
aws-actions/[email protected]
102
+ if : ${{ steps.is-version-already-deployed.outputs.is_deployed == 'false'}}
83
103
with :
84
104
aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID_FRONTEND_REGISTRY }}
85
105
aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY_FRONTEND_REGISTRY }}
86
106
aws-region : eu-west-1
87
107
88
108
- name : Download & Unpack Bundle
109
+ if : ${{ steps.is-version-already-deployed.outputs.is_deployed == 'false'}}
89
110
run : |
90
111
aws s3 cp ${{ inputs.bundle_uri }} bundle.tar.gz
91
112
mkdir ${{ inputs.bundle_dir }} && tar -xvzf bundle.tar.gz -C ${{ inputs.bundle_dir }}
@@ -98,45 +119,57 @@ jobs:
98
119
aws-region : eu-west-1
99
120
100
121
- name : Inject Environment Config
101
- if : inputs.inject_config_cmd
122
+ if : inputs.inject_config_cmd && ${{ steps.is-version-already-deployed.outputs.is_deployed == 'false'}}
102
123
env :
103
124
NODE_AUTH_TOKEN : ${{ secrets.GH_REGISTRY_NPM_TOKEN }}
104
125
SPA_BUNDLE_DIR : ${{ inputs.bundle_dir }}
105
126
SPA_ENV : ${{inputs.environment}}
106
- SPA_TREE_HASH : ${{ inputs.tree_hash }}
127
+ SPA_TREE_HASH : ${{ inputs.deploy_hash }}
107
128
run : ${{inputs.inject_config_cmd }}
108
129
109
130
- name : Copy Static Files
131
+ if : ${{ steps.is-version-already-deployed.outputs.is_deployed == 'false'}}
110
132
run : |
111
133
aws s3 cp ${{ inputs.bundle_dir }}/static s3://${{ inputs.bucket_name }}/static \
112
134
--cache-control 'public,max-age=31536000,immutable' \
113
135
--recursive
114
136
115
137
- name : Copy HTML Files
138
+ if : ${{ steps.is-version-already-deployed.outputs.is_deployed == 'false'}}
116
139
run : |
117
- 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 }} \
118
141
--cache-control 'public,max-age=31536000,immutable' \
119
142
--recursive \
120
143
--exclude "static/*"
121
144
122
145
- name : Update .well-known Files If Exists
146
+ if : ${{ steps.is-version-already-deployed.outputs.is_deployed == 'false'}}
123
147
run : |
124
148
aws s3 cp \
125
- s3://${{ inputs.bucket_name }}/html/${{ inputs.tree_hash }}/.well-known/apple-app-site-association \
126
- 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 \
127
151
--content-type 'application/json' \
128
152
--cache-control 'public,max-age=3600' \
129
153
--metadata-directive REPLACE || echo "Failed updating .well-known files"
130
154
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
+
131
163
- name : Update Cursor File
132
164
id : cursor-update
133
- uses :
pleo-io/spa-tools/actions/[email protected]
165
+ uses :
pleo-io/spa-tools/actions/[email protected]
166
+ if : ${{ steps.is-version-already-deployed.outputs.is_deployed == 'false'}}
134
167
with :
135
168
bucket_name : ${{ inputs.bucket_name }}
136
169
137
170
- name : Update PR Description
138
- uses : pleo-io/spa-tools/actions/post-preview-urls@spa-github-actions-v9 .0.2
139
- if : github.event_name == 'pull_request'
171
+ uses : pleo-io/spa-tools/actions/post-preview-urls@spa-github-actions-v10 .0.0
172
+ if : github.event_name == 'pull_request' && ${{ steps.is-version-already-deployed.outputs.is_deployed == 'false'}}
140
173
with :
141
174
app_name : ${{ inputs.app_name }}
142
175
links : |
@@ -145,15 +178,8 @@ jobs:
145
178
{"name": "Current Permalink", "url": "${{ steps.deployment-url.outputs.url }}"}
146
179
]
147
180
148
- - name : Upload Deployed Bundle as Artifact
149
-
150
- with :
151
- name : bundle-${{ inputs.tree_hash }}-${{ inputs.environment }}
152
- path : bundle.tar.gz
153
-
154
181
- name : Verify app deployment
155
- if : inputs.inject_config_cmd
182
+ if : inputs.inject_config_cmd && ${{ steps.is-version-already-deployed.outputs.is_deployed == 'false'}}
156
183
# We expect the injection to insert the version in the HTML.
157
- run :
158
- curl --silent --show-error ${{ steps.deployment-url.outputs.url }} |
159
- grep -q ${{ inputs.tree_hash }}
184
+ run : curl --silent --show-error ${{ steps.deployment-url.outputs.url }} |
185
+ grep -q ${{ inputs.deploy_hash }}
0 commit comments