|
| 1 | +name: Publish & Release |
| 2 | + |
| 3 | +on: workflow_dispatch |
| 4 | + |
| 5 | +jobs: |
| 6 | + build: |
| 7 | + name: Build |
| 8 | + runs-on: ubuntu-latest |
| 9 | + steps: |
| 10 | + - name: Checkout |
| 11 | + uses: actions/checkout@v4 |
| 12 | + |
| 13 | + - name: Setup node |
| 14 | + uses: actions/setup-node@v4 |
| 15 | + with: |
| 16 | + node-version: 20 |
| 17 | + cache: yarn |
| 18 | + env: |
| 19 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 20 | + |
| 21 | + - name: Install dependencies |
| 22 | + run: | |
| 23 | + yarn config set network-timeout 300000 |
| 24 | + yarn install --prefer-offline |
| 25 | + env: |
| 26 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 27 | + |
| 28 | + - name: Build |
| 29 | + continue-on-error: false |
| 30 | + run: yarn build |
| 31 | + env: |
| 32 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 33 | + |
| 34 | + - name: Upload artifact |
| 35 | + uses: actions/upload-artifact@v4 |
| 36 | + with: |
| 37 | + name: dist |
| 38 | + path: dist |
| 39 | + retention-days: 30 |
| 40 | + |
| 41 | + push: |
| 42 | + name: Push |
| 43 | + needs: build |
| 44 | + runs-on: ubuntu-latest |
| 45 | + permissions: |
| 46 | + contents: write |
| 47 | + env: |
| 48 | + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} |
| 49 | + steps: |
| 50 | + - name: Checkout |
| 51 | + uses: actions/checkout@v4 |
| 52 | + |
| 53 | + - name: Download artifact |
| 54 | + uses: actions/download-artifact@v4 |
| 55 | + with: |
| 56 | + name: dist |
| 57 | + path: dist |
| 58 | + |
| 59 | + - name: Push distribution |
| 60 | + run: | |
| 61 | + MSG="$(printf "Publish distribution\n[skip ci]")" |
| 62 | + git config --global user.name "github-actions[bot]" |
| 63 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 64 | + git add dist/index.min.* -f |
| 65 | + git diff-index --quiet HEAD || git commit -m "$MSG" --no-verify --signoff |
| 66 | + git push origin $BRANCH_NAME |
| 67 | +
|
| 68 | + deploy: |
| 69 | + name: Deploy |
| 70 | + needs: build |
| 71 | + runs-on: ubuntu-latest |
| 72 | + permissions: |
| 73 | + id-token: write |
| 74 | + contents: read |
| 75 | + steps: |
| 76 | + - name: Checkout |
| 77 | + uses: actions/checkout@v4 |
| 78 | + |
| 79 | + - name: Download artifact |
| 80 | + uses: actions/download-artifact@v4 |
| 81 | + with: |
| 82 | + name: dist |
| 83 | + path: dist |
| 84 | + |
| 85 | + - name: Configure AWS credentials |
| 86 | + uses: aws-actions/configure-aws-credentials@v4 |
| 87 | + with: |
| 88 | + role-to-assume: ${{ secrets.AWS_GITHUB_ACTION_ROLE }} |
| 89 | + aws-region: us-east-2 |
| 90 | + |
| 91 | + - name: Sync files to S3 bucket |
| 92 | + run: | |
| 93 | + PACKAGE_VERSION=$(npm pkg get version --workspaces=false | tr -d \") |
| 94 | + aws s3 sync dist s3://cdn.zigurous.com/forge-react@$PACKAGE_VERSION/dist --delete --exclude "*.ts" |
| 95 | +
|
| 96 | + publish: |
| 97 | + name: Publish |
| 98 | + needs: [push, deploy] |
| 99 | + runs-on: ubuntu-latest |
| 100 | + steps: |
| 101 | + - name: Checkout |
| 102 | + uses: actions/checkout@v4 |
| 103 | + |
| 104 | + - name: Download artifact |
| 105 | + uses: actions/download-artifact@v4 |
| 106 | + with: |
| 107 | + name: dist |
| 108 | + path: dist |
| 109 | + |
| 110 | + - name: Setup node |
| 111 | + uses: actions/setup-node@v4 |
| 112 | + with: |
| 113 | + node-version: 20 |
| 114 | + cache: yarn |
| 115 | + env: |
| 116 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 117 | + |
| 118 | + - name: Install dependencies |
| 119 | + run: | |
| 120 | + yarn config set network-timeout 300000 |
| 121 | + yarn install --prefer-offline |
| 122 | + env: |
| 123 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 124 | + |
| 125 | + - name: Publish to NPM |
| 126 | + run: | |
| 127 | + npm publish |
| 128 | + env: |
| 129 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 130 | + |
| 131 | + release: |
| 132 | + name: Release |
| 133 | + needs: publish |
| 134 | + runs-on: ubuntu-latest |
| 135 | + steps: |
| 136 | + - name: Checkout |
| 137 | + uses: actions/checkout@v4 |
| 138 | + |
| 139 | + - name: Create release |
| 140 | + env: |
| 141 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 142 | + run: | |
| 143 | + PACKAGE_VERSION=$(npm pkg get version --workspaces=false | tr -d \") |
| 144 | + gh release create "$PACKAGE_VERSION" \ |
| 145 | + --target ${{ github.ref_name }} \ |
| 146 | + --title "$PACKAGE_VERSION" \ |
| 147 | + --latest |
0 commit comments