Publish tokens #83
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish tokens | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
paths: | |
- 'package.json' | |
permissions: | |
id-token: write | |
contents: read | |
env: | |
CDN_BUCKET: gc-design-system-production-cdn | |
CDN_REGION: ca-central-1 | |
PACKAGE_NAME: '@cdssnc/gcds-tokens' | |
jobs: | |
build-deploy: | |
name: Publish package | |
runs-on: ubuntu-latest | |
steps: | |
- name: Git Checkout | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Check if package exists | |
id: package_exists | |
run: | | |
if npm show ${{ env.PACKAGE_NAME }}@${{ steps.publish.outputs.id }} > /dev/null 2>&1; then | |
echo "pkg_exists=true" >> $GITHUB_ENV | |
else | |
echo "pkg_exists=false" >> $GITHUB_ENV | |
- name: Publish | |
if: env.pkg_exists != 'true' | |
uses: JS-DevTools/npm-publish@e06fe3ef65499b38eb12224f2a60979f6d797330 | |
id: publish | |
with: | |
token: ${{ secrets.NPM_TOKEN }} | |
- name: Sleep for 60 seconds to give more time for NPM to complete publishing before proceeding to publish the rest | |
if: env.pkg_exists != 'true' | |
run: sleep 60 | |
- name: Configure AWS credentials using OIDC | |
if: steps.publish.outputs.id != '' | |
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2 | |
with: | |
role-to-assume: arn:aws:iam::307395567143:role/gcds-tokens-apply | |
role-session-name: CDNPublish | |
aws-region: ${{ env.CDN_REGION }} | |
- name: Update CDN | |
if: steps.publish.outputs.id != '' | |
run: | | |
PUBLISHED_PACKAGE="${{ steps.publish.outputs.id }}" | |
mkdir -p ./tmp \ | |
&& sleep 60 \ | |
&& npm install --prefix ./tmp "$PUBLISHED_PACKAGE" \ | |
&& cd ./tmp/node_modules | |
aws s3 sync ./${{ env.PACKAGE_NAME }} s3://${{ env.CDN_BUCKET }}/"$PUBLISHED_PACKAGE" --delete | |
aws s3 sync ./${{ env.PACKAGE_NAME }} s3://${{ env.CDN_BUCKET }}/${{ env.PACKAGE_NAME }}@latest --delete | |
aws s3api head-object --bucket ${{ env.CDN_BUCKET }} --key "$PUBLISHED_PACKAGE"/package.json | |
aws s3api head-object --bucket ${{ env.CDN_BUCKET }} --key ${{ env.PACKAGE_NAME }}@latest/package.json | |
aws cloudfront create-invalidation --distribution-id ${{ secrets.CDN_CLOUDFRONT_DIST_ID }} --paths "/*" | |
- name: Report deployment to Sentinel | |
if: steps.publish.outputs.id != '' | |
uses: cds-snc/sentinel-forward-data-action@main | |
with: | |
input_data: '{"product": "design-system", "sha": "${{ github.sha }}", "version": "${{steps.publish.outputs.id}}", "repository": "${{ github.repository }}", "environment": "production", "status": "${{ job.status }}"}' | |
log_type: CDS_Product_Deployment_Data | |
log_analytics_workspace_id: ${{ secrets.LOG_ANALYTICS_WORKSPACE_ID }} | |
log_analytics_workspace_key: ${{ secrets.LOG_ANALYTICS_WORKSPACE_KEY }} | |
- name: Slack notify on failure | |
if: failure() | |
run: | | |
json='{"blocks":[{"type":"section","text":{"type":"mrkdwn","text":":red: Publish @cdssnc/gcds-tokens failed: <https://github.com/cds-snc/gcds-tokens/actions/workflows/publish.yml|Publish tokens>"}}]}' | |
curl -X POST -H 'Content-type: application/json' --data "$json" ${{ secrets.SLACK_WEBHOOK_OPS }} | |
- name: Slack notify on release and publish | |
if: steps.publish.outputs.id != '' | |
run: | | |
VERSION=$(jq -r '.version' package.json) | |
json='{"text":"🚀 New release available! @cdssnc/gcds-tokens *version <https://github.com/cds-snc/gcds-tokens/releases/tag/gcds-tokens-v'$VERSION'|${{steps.publish.outputs.id}}>*"}' | |
echo "Posting to slack: $json" | |
curl -X POST -H 'Content-type: application/json' --data "$json" ${{ secrets.SLACK_WEBHOOK_DSNDEV }} |