|
| 1 | +name: "Setup environment" |
| 2 | +description: "Checks out code, sets up Node.js, and builds the project or fetches cached build artifacts, caching build artifacts for faster subsequent runs" |
| 3 | + |
| 4 | +inputs: |
| 5 | + operation: |
| 6 | + description: "The operation to perform. Can be 'build' or 'fetch' (default: 'fetch')." |
| 7 | + required: true |
| 8 | + default: "fetch" |
| 9 | + values: |
| 10 | + - "build" |
| 11 | + - "fetch" |
| 12 | + |
| 13 | +runs: |
| 14 | + using: "composite" |
| 15 | + steps: |
| 16 | + - name: Setup Node.js |
| 17 | + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 |
| 18 | + with: |
| 19 | + node-version: 24 |
| 20 | + cache: "npm" |
| 21 | + |
| 22 | + - name: Get Bundle Artifacts Name |
| 23 | + id: get-artifacts-name |
| 24 | + shell: bash |
| 25 | + env: |
| 26 | + bundle_artifacts_name: "action-bundle-${{ github.event.pull_request.head.sha || github.sha }}" |
| 27 | + run: | |
| 28 | + echo "bundle-artifacts-name=${{ env.bundle_artifacts_name }}" >> $GITHUB_ENV |
| 29 | +
|
| 30 | + - name: Try Fetch Bundle Artifacts |
| 31 | + if: ${{ inputs.operation == 'fetch' }} |
| 32 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 33 | + continue-on-error: true |
| 34 | + with: |
| 35 | + name: ${{ env.bundle-artifacts-name }} |
| 36 | + |
| 37 | + - name: Check Fetch Bundle Artifacts |
| 38 | + id: check-artifact |
| 39 | + shell: bash |
| 40 | + run: | |
| 41 | + if [ -d "dist" ] && [ "$(ls -A dist)" ]; then |
| 42 | + echo "artifacts_present=true" >> $GITHUB_ENV |
| 43 | + else |
| 44 | + echo "artifacts_present=false" >> $GITHUB_ENV |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Fail Fetch Bundle Artifacts |
| 48 | + if: ${{ inputs.operation == 'fetch' && env.artifacts_present == 'false' }} |
| 49 | + shell: bash |
| 50 | + run: | |
| 51 | + echo "No artifacts found for the current commit. Please run the workflow with 'build' operation first." |
| 52 | + exit 1 |
| 53 | +
|
| 54 | + - name: Bundle Action |
| 55 | + if: ${{ inputs.operation == 'build' && env.artifacts_present == 'false' }} |
| 56 | + shell: bash |
| 57 | + run: npm run bundle |
| 58 | + |
| 59 | + - name: Upload Bundle Artifacts |
| 60 | + if: ${{ inputs.operation == 'build' && env.artifacts_present == 'false' }} |
| 61 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 62 | + with: |
| 63 | + name: ${{ env.bundle-artifacts-name }} |
| 64 | + path: | |
| 65 | + action.yml |
| 66 | + dist/ |
| 67 | + retention-days: 1 |
0 commit comments