|
| 1 | +name: |- |
| 2 | + CI - GitHub Action |
| 3 | + |
| 4 | + Lint and test github action |
| 5 | + |
| 6 | + ### Usage |
| 7 | + ```yaml |
| 8 | + name: Validate Terraform |
| 9 | + on: |
| 10 | + workflow_call: |
| 11 | + |
| 12 | + permissions: |
| 13 | + pull-requests: write |
| 14 | + id-token: write |
| 15 | + contents: read |
| 16 | + |
| 17 | + jobs: |
| 18 | + ci-terraform: |
| 19 | + uses: cloudposse/github-actions-workflows/.github/workflows/ci-terraform.yml@main |
| 20 | + with: |
| 21 | + suggestions: true |
| 22 | + filter-mode: diff_context |
| 23 | + ``` |
| 24 | +on: |
| 25 | + workflow_call: |
| 26 | + inputs: |
| 27 | + organization: |
| 28 | + description: "Repository owner organization (ex. acme for repo acme/example)" |
| 29 | + required: false |
| 30 | + default: ${{ github.event.repository.owner.login }} |
| 31 | + type: string |
| 32 | + repository: |
| 33 | + description: "Repository name (ex. example for repo acme/example)" |
| 34 | + required: false |
| 35 | + default: ${{ github.event.repository.name }} |
| 36 | + type: string |
| 37 | + ref: |
| 38 | + description: "The fully-formed ref of the branch or tag that triggered the workflow run" |
| 39 | + required: false |
| 40 | + default: ${{ github.ref }} |
| 41 | + type: string |
| 42 | + tests-prefix: |
| 43 | + description: "Workflows file name prefix to run as tests" |
| 44 | + required: false |
| 45 | + type: string |
| 46 | + default: 'test-*' |
| 47 | + runs-on: |
| 48 | + description: "Overrides job runs-on setting (json-encoded list)" |
| 49 | + type: string |
| 50 | + required: false |
| 51 | + default: '["ubuntu-latest"]' |
| 52 | + |
| 53 | +permissions: |
| 54 | + contents: write |
| 55 | + actions: write |
| 56 | + |
| 57 | +jobs: |
| 58 | + context: |
| 59 | + runs-on: ${{ fromJSON(inputs.runs-on) }} |
| 60 | + steps: |
| 61 | + - name: Checkout main |
| 62 | + uses: actions/checkout@v4 |
| 63 | + |
| 64 | + - name: Workflows |
| 65 | + id: workflows |
| 66 | + shell: bash |
| 67 | + run: | |
| 68 | + TEST_FILES=$(find ./.github/workflows -type f -name "${{ inputs.tests-prefix }}" -exec basename {} \; | jq -MRc -s '. | split("\n") | map(select(. != ""))') |
| 69 | + echo "list=${TEST_FILES}" >> $GITHUB_OUTPUT |
| 70 | +
|
| 71 | + outputs: |
| 72 | + tests: ${{ steps.workflows.outputs.list }} |
| 73 | + |
| 74 | + lint: |
| 75 | + runs-on: ${{ fromJSON(inputs.runs-on) }} |
| 76 | + steps: |
| 77 | + - name: Checkout |
| 78 | + uses: actions/checkout@v4 |
| 79 | + |
| 80 | + - name: YAML file validation |
| 81 | + uses: mpoc/nexus-validate-using-remote-schema-action@main |
| 82 | + with: |
| 83 | + api-endpoint: https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/github-action.json |
| 84 | + yaml-file: action.yml |
| 85 | + |
| 86 | + test: |
| 87 | + runs-on: ${{ fromJSON(inputs.runs-on) }} |
| 88 | + if: ${{ needs.context.outputs.tests != '[]' }} |
| 89 | + strategy: |
| 90 | + matrix: |
| 91 | + env: ${{ fromJson(needs.context.outputs.tests) }} |
| 92 | + needs: [ lint, context ] |
| 93 | + steps: |
| 94 | + - uses: convictional/[email protected] |
| 95 | + with: |
| 96 | + owner: ${{ inputs.organization }} |
| 97 | + repo: ${{ inputs.repository }} |
| 98 | + github_token: ${{ github.token }} |
| 99 | + workflow_file_name: ${{ matrix.env }} |
| 100 | + ref: ${{ inputs.ref }} |
| 101 | + wait_interval: 10 |
| 102 | + client_payload: '{}' |
| 103 | + propagate_failure: true |
| 104 | + trigger_workflow: true |
| 105 | + wait_workflow: true |
0 commit comments