diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index cf29a58..e8612b2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,49 +1,28 @@ -name: CI +name: Lint on: - pull_request: - branches: [main] + workflow_call: + inputs: + runner: + required: false + default: "['ubuntu-latest']" + type: string -jobs: - lint: - name: Lint - runs-on: ubuntu-latest - steps: - - uses: open-turo/actions-gha/lint@v2 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Check release notes on pull_request - if: github.event_name == 'pull_request' - uses: open-turo/actions-release/lint-release-notes@v4 + secrets: + github-token: + required: true - test: - name: Test - runs-on: ubuntu-latest +jobs: + pre-commit: + runs-on: ${{ fromJson(inputs.runner) }} steps: - - uses: open-turo/actions-gha/test@v2 + - uses: open-turo/actions-python/pre-commit@feat/run-actions-in-parallel with: - github-token: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{ secrets.github-token }} - # lint-oss tries to run this action against open source repositories not in - # open-turo to make sure this is usable outside the org. - # Repositories added to this list should have pre-commit hooks that don't - # require external tooling to be installed. - # Repositories added to this list must have passing pre-commit hooks. - lint-oss: - name: Lint / Open source - runs-on: ubuntu-latest - strategy: - matrix: - repos: - - tiangolo/fastapi + commitlint: + runs-on: ${{ fromJson(inputs.runner) }} steps: - - uses: actions/checkout@v4 - with: - repository: ${{ matrix.repos }} - - uses: actions/checkout@v4 - with: - path: actions-python - - uses: ./actions-python/lint + - uses: open-turo/actions-python/pre-commit@feat/run-actions-in-parallel with: - checkout-repo: false - github-token: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{ secrets.github-token }} diff --git a/.github/workflows/repo-ci.yaml b/.github/workflows/repo-ci.yaml new file mode 100644 index 0000000..cf29a58 --- /dev/null +++ b/.github/workflows/repo-ci.yaml @@ -0,0 +1,49 @@ +name: CI + +on: + pull_request: + branches: [main] + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: open-turo/actions-gha/lint@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Check release notes on pull_request + if: github.event_name == 'pull_request' + uses: open-turo/actions-release/lint-release-notes@v4 + + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: open-turo/actions-gha/test@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + + # lint-oss tries to run this action against open source repositories not in + # open-turo to make sure this is usable outside the org. + # Repositories added to this list should have pre-commit hooks that don't + # require external tooling to be installed. + # Repositories added to this list must have passing pre-commit hooks. + lint-oss: + name: Lint / Open source + runs-on: ubuntu-latest + strategy: + matrix: + repos: + - tiangolo/fastapi + steps: + - uses: actions/checkout@v4 + with: + repository: ${{ matrix.repos }} + - uses: actions/checkout@v4 + with: + path: actions-python + - uses: ./actions-python/lint + with: + checkout-repo: false + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/repo-release.yaml similarity index 100% rename from .github/workflows/release.yaml rename to .github/workflows/repo-release.yaml diff --git a/commitlint/action.yaml b/commitlint/action.yaml new file mode 100644 index 0000000..9850e92 --- /dev/null +++ b/commitlint/action.yaml @@ -0,0 +1,27 @@ +name: "Commitlint Action" +description: "Lint commit messages using commitlint" +inputs: + node-version: + description: "Node version" + required: false + default: "16" +runs: + using: "composite" + steps: + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.node-version }} + - name: Install commitlint + run: npm install --save-dev @commitlint/cli @commitlint/config-conventional @open-turo/commitlint-config-conventional + shell: bash + - name: Run commitlint for pull requests + if: ${{ github.event_name == 'pull_request' }} + run: | + npx commitlint --from origin/${{ github.base_ref }} --to HEAD --verbose + shell: bash + - name: Run commitlint for push to main + if: ${{ github.event_name == 'push' }} + run: | + npx commitlint --from ${{ github.event.before }} --to ${{ github.event.after }} --verbose + shell: bash diff --git a/pre-commit/action.yaml b/pre-commit/action.yaml new file mode 100644 index 0000000..852a2f3 --- /dev/null +++ b/pre-commit/action.yaml @@ -0,0 +1,31 @@ +name: "Pre-commit Action" +description: "Run pre-commit in your GitHub Actions workflow" +inputs: + python-version: + description: "Python version" + required: false + default: "3.11" + extra_args: + description: "Extra arguments to pass to pre-commit" + required: false + default: "" + +runs: + using: "composite" + steps: + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python-version }} + - name: Install pre-commit + run: pip install pre-commit + shell: bash + # #cache pre-commit cache + # - name: Cache pre-commit cache + # uses: actions/cache@v4 + # with: + # path: ~/.cache/pre-commit + # key: pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }} + - name: Run pre-commit + run: pre-commit run --show-diff-on-failure --color=always ${{ inputs.extra_args }} + shell: bash