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