|
| 1 | + |
| 2 | +name: Publish Experiment Packages Branch to S3 |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + branch: |
| 8 | + description: 'Branch to deploy from' |
| 9 | + required: true |
| 10 | + type: string |
| 11 | + default: 'main' |
| 12 | + includeTag: |
| 13 | + description: 'Include experiment-tag package' |
| 14 | + type: boolean |
| 15 | + required: true |
| 16 | + default: true |
| 17 | + includeSegmentPlugin: |
| 18 | + description: 'Include experiment-plugin-segment package' |
| 19 | + type: boolean |
| 20 | + required: true |
| 21 | + default: true |
| 22 | + |
| 23 | +jobs: |
| 24 | + authorize: |
| 25 | + name: Authorize |
| 26 | + runs-on: ubuntu-latest |
| 27 | + steps: |
| 28 | + - name: ${{ github.actor }} permission check |
| 29 | + uses: 'lannonbr/[email protected]' |
| 30 | + with: |
| 31 | + permission: 'write' |
| 32 | + env: |
| 33 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 34 | + |
| 35 | + build-and-deploy: |
| 36 | + runs-on: ubuntu-latest |
| 37 | + needs: [authorize] |
| 38 | + permissions: |
| 39 | + id-token: write |
| 40 | + contents: read |
| 41 | + steps: |
| 42 | + - name: Checkout |
| 43 | + uses: actions/checkout@v3 |
| 44 | + with: |
| 45 | + ref: ${{ github.event.inputs.branch }} |
| 46 | + |
| 47 | + - name: Setup Node |
| 48 | + uses: actions/setup-node@v3 |
| 49 | + with: |
| 50 | + node-version: '18' |
| 51 | + cache: 'yarn' |
| 52 | + |
| 53 | + - name: Set up SSH for deploy key |
| 54 | + run: | |
| 55 | + mkdir -p ~/.ssh |
| 56 | + echo "${{ secrets.DOM_MUTATOR_ACCESS_KEY }}" > ~/.ssh/id_ed25519 |
| 57 | + chmod 600 ~/.ssh/id_ed25519 |
| 58 | + ssh-keyscan github.com >> ~/.ssh/known_hosts |
| 59 | +
|
| 60 | + - name: Install dependencies |
| 61 | + run: yarn install --frozen-lockfile |
| 62 | + |
| 63 | + - name: Install AWS SDK dependencies |
| 64 | + run: cd scripts && yarn install |
| 65 | + |
| 66 | + - name: Build experiment-tag |
| 67 | + if: ${{ github.event.inputs.includeTag == 'true' }} |
| 68 | + run: cd packages/experiment-tag && yarn build |
| 69 | + |
| 70 | + - name: Build experiment-plugin-segment |
| 71 | + if: ${{ github.event.inputs.includeSegmentPlugin == 'true' }} |
| 72 | + run: cd packages/plugin-segment && yarn build |
| 73 | + |
| 74 | + - name: Get branch name |
| 75 | + id: branch-name |
| 76 | + run: | |
| 77 | + BRANCH_NAME="${{ github.event.inputs.branch }}" |
| 78 | + # If branch is main, set branch name to empty string to strip it from the filename |
| 79 | + if [[ "$BRANCH_NAME" == "main" ]]; then |
| 80 | + echo "branch_name_safe=" >> $GITHUB_OUTPUT |
| 81 | + else |
| 82 | + # Replace slashes with dashes for S3 key compatibility |
| 83 | + BRANCH_NAME_SAFE=$(echo $BRANCH_NAME | sed 's/\//-/g') |
| 84 | + echo "branch_name_safe=$BRANCH_NAME_SAFE" >> $GITHUB_OUTPUT |
| 85 | + fi |
| 86 | +
|
| 87 | + - name: Determine packages to upload |
| 88 | + id: packages-to-upload |
| 89 | + run: | |
| 90 | + PACKAGES="" |
| 91 | + if [[ "${{ github.event.inputs.includeTag }}" == "true" ]]; then |
| 92 | + PACKAGES="tag" |
| 93 | + fi |
| 94 | + |
| 95 | + if [[ "${{ github.event.inputs.includeSegmentPlugin }}" == "true" ]]; then |
| 96 | + if [[ -n "$PACKAGES" ]]; then |
| 97 | + PACKAGES="$PACKAGES,segment-plugin" |
| 98 | + else |
| 99 | + PACKAGES="segment-plugin" |
| 100 | + fi |
| 101 | + fi |
| 102 | + |
| 103 | + if [[ -z "$PACKAGES" ]]; then |
| 104 | + echo "No packages selected for upload" |
| 105 | + exit 1 |
| 106 | + fi |
| 107 | + |
| 108 | + echo "packages=$PACKAGES" >> $GITHUB_OUTPUT |
| 109 | +
|
| 110 | + - name: Configure AWS Credentials |
| 111 | + uses: aws-actions/configure-aws-credentials@v2 |
| 112 | + with: |
| 113 | + role-to-assume: ${{ secrets.AWS_ROLE_ARN }} |
| 114 | + aws-region: us-west-2 |
| 115 | + |
| 116 | + - name: Upload to S3 with branch name |
| 117 | + env: |
| 118 | + S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }} |
| 119 | + BRANCH_NAME: ${{ steps.branch-name.outputs.branch_name_safe }} |
| 120 | + PACKAGES: ${{ steps.packages-to-upload.outputs.packages }} |
| 121 | + run: node scripts/upload-to-s3.js |
0 commit comments