|
| 1 | +name: 'Publish: Publish to CDN' |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: {} |
| 5 | + |
| 6 | +# It's required to set permissions to be able to: |
| 7 | +# - Authenticate to AWS with OIDC |
| 8 | +# See: https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services |
| 9 | +permissions: |
| 10 | + id-token: write |
| 11 | + contents: read |
| 12 | + |
| 13 | +jobs: |
| 14 | + publish-to-cdn: |
| 15 | + name: Publish to CDN |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Configure AWS credentials |
| 21 | + uses: aws-actions/configure-aws-credentials@010d0da01d0b5a38af31e9c3470dbfdabdecca3a # v4.0.1 |
| 22 | + with: |
| 23 | + role-to-assume: ${{ secrets.AWS_GHA_ROLE }} |
| 24 | + role-session-name: constructorio-client-javascript-cdn-publish |
| 25 | + aws-region: us-east-1 |
| 26 | + |
| 27 | + - name: Copy files to s3 |
| 28 | + id: copy-files |
| 29 | + shell: bash |
| 30 | + run: | |
| 31 | + # Create a new directory for s3 sync |
| 32 | + mkdir s3_dist |
| 33 | +
|
| 34 | + # Get the version and copy files |
| 35 | + VERSION=$(ls dist/constructorio-client-javascript-*.js | sed 's/.*javascript-\(.*\)\.js/\1/') |
| 36 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 37 | +
|
| 38 | + # Copy the bundled file with version number |
| 39 | + cp dist/constructorio-client-javascript-$VERSION.js s3_dist/$VERSION.js |
| 40 | +
|
| 41 | + # Also create a latest version for easy access |
| 42 | + cp dist/constructorio-client-javascript-$VERSION.js s3_dist/latest.js |
| 43 | +
|
| 44 | + # Sync to S3 with appropriate caching and permissions |
| 45 | + aws s3 sync s3_dist s3://constructor-frontend-prod/sdk/client-javascript --cache-control 'public, max-age=31536000, immutable' --acl 'public-read' |
| 46 | +
|
| 47 | + - name: Notify Slack about new publish to CDN |
| 48 | + uses: ravsamhq/notify-slack-action@bca2d7f5660b25833a27bda4f6b8bef389ebfefd25 # v2.3.0 |
| 49 | + with: |
| 50 | + notification_title: "☁️ New constructorio-client-javascript release published to CDN at version ${{ steps.copy-files.outputs.version }}" |
| 51 | + status: ${{ job.status }} |
| 52 | + footer: "CDN URL: https://cdn.constructor.io/sdk/client-javascript/${{ steps.copy-files.outputs.version }}.js" |
| 53 | + env: |
| 54 | + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |
0 commit comments