|
1 | | -# initialize-action |
| 1 | +# initialize-action |
| 2 | + |
| 3 | +## Description |
| 4 | + |
| 5 | +The **Initialize Action** sets up the environment for your workflow, cancels previous runs, and generates a project matrix for subsequent jobs. This action is designed to streamline your CI/CD pipeline by managing previous workflow executions and creating a dynamic project matrix based on changed files. |
| 6 | + |
| 7 | +## Inputs |
| 8 | + |
| 9 | +| Input | Description | Required | Default | |
| 10 | +|-------|-------------|----------|---------| |
| 11 | +| `project-root` | Project root folder | No | `.` | |
| 12 | +| `script-version` | Version of the script to use | No | `0.5.1` | |
| 13 | + |
| 14 | +## Outputs |
| 15 | + |
| 16 | +| Output | Description | |
| 17 | +|--------|-------------| |
| 18 | +| `matrix` | The project matrix for subsequent jobs | |
| 19 | +| `files` | List of changed files | |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +``` |
| 24 | +name: CI Workflow |
| 25 | +
|
| 26 | +on: |
| 27 | + push: |
| 28 | + branches: |
| 29 | + - main |
| 30 | + - develop |
| 31 | +
|
| 32 | +jobs: |
| 33 | + initialize: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + steps: |
| 36 | + - name: Checkout code |
| 37 | + uses: actions/checkout@v2 |
| 38 | + |
| 39 | + - name: Initialize Action |
| 40 | + uses: your-username/initialize-action@v0.1 |
| 41 | + with: |
| 42 | + project-root: 'your/project/root' |
| 43 | + script-version: '0.5.1' |
| 44 | + |
| 45 | + # Additional steps to use the outputs can go here |
| 46 | +``` |
| 47 | + |
| 48 | +## Steps |
| 49 | + |
| 50 | +Steps |
| 51 | +1. **Cancel Previous Runs**: This step cancels any previous runs if the current branch is not `develop` or `main`. |
| 52 | +1. **Download Scripts**: The action downloads the specified version of the necessary scripts. |
| 53 | +1. **Unzip Scripts**: This step extracts the downloaded scripts from the zip file. |
| 54 | +1. **List Modified Files**: Uses the `tj-actions/changed-files` action to gather all modified files and processes them. |
| 55 | +1. **Set Dynamic Matrix**: This step generates a project matrix based on the modified files and outputs it for use in subsequent jobs. |
| 56 | + |
| 57 | +## Example |
| 58 | + |
| 59 | +Here's an example of how you can utilize the outputs of the Initialize Action in your workflow: |
| 60 | + |
| 61 | +``` |
| 62 | +name: Continuous Integration & Delivery |
| 63 | +
|
| 64 | +on: |
| 65 | + push: |
| 66 | + branches: |
| 67 | + - main |
| 68 | + pull_request: |
| 69 | + branches: |
| 70 | + - main |
| 71 | +
|
| 72 | +jobs: |
| 73 | + initialize: |
| 74 | + runs-on: ubuntu-latest |
| 75 | + timeout-minutes: 15 |
| 76 | + steps: |
| 77 | + - uses: actions/checkout@v4 |
| 78 | + - name: initialize |
| 79 | + id: initialize |
| 80 | + uses: robaone/initialize-action@v0.3.7 |
| 81 | + with: |
| 82 | + project-root: . |
| 83 | + script-version: 0.5.1 |
| 84 | + outputs: |
| 85 | + matrix: ${{ steps.initialize.outputs.matrix }} |
| 86 | + unit-tests: |
| 87 | + needs: [initialize] |
| 88 | + strategy: |
| 89 | + matrix: ${{ fromJson(needs.initialize.outputs.matrix) }} |
| 90 | + runs-on: ubuntu-latest |
| 91 | + timeout-minutes: 15 |
| 92 | + steps: |
| 93 | + - uses: actions/checkout@v4 |
| 94 | +``` |
| 95 | + |
0 commit comments