Skip to content

Commit

Permalink
Convert from composite to typescript (#17)
Browse files Browse the repository at this point in the history
# Summary

Converts the action from a [composite to
javascript](https://docs.github.com/en/actions/sharing-automations/creating-actions/about-custom-actions#types-of-actions).
Most importantly to make use of prebuilt libraries and helpers like
[actions/toolkit](https://github.com/actions/toolkit).

The structure and features are modeled after
[astral-sh/setup-uv](https://github.com/astral-sh/setup-uv)

## Changes

1. Download the ruff executable for the current platform from the GitHub
releases
2. Add ruff to the PATH
3. Validate the downloaded ruff executable against its checksum
4. Cache ruff in the [Tool
Cache](https://github.com/actions/toolkit/tree/main/packages/tool-cache)
to speed up runs on self-hosted runners
5. Support semver ranges to define the ruff version to install

## 🚨 Breaking changes

Removes the `changed-files` input.

This input could previously be used to run ruff only on files changed in
a PR. The functionality was implemented by calling another action. This
repo should focus on providing a quick and easy way to use ruff in
GitHub Actions, not add more functionality on top of ruff.

The previous functionality can be replicated with:

```yaml
- uses: actions/checkout@v4
- name: Get changed files
  id: changed-files
  uses: tj-actions/changed-files@v45
  with:
    files: |
      **.py
- name: Run ruff on changed files only 
  uses: astral-sh/ruff-action@v2
  with:
    src: ${{ steps.changed-files.outputs.all_changed_files }}
```

This was tested here:
https://github.com/astral-sh/ruff-action/actions/runs/12017035736/job/33498508269
  • Loading branch information
eifinger authored Dec 3, 2024
1 parent d0a0e81 commit f2e3221
Show file tree
Hide file tree
Showing 44 changed files with 78,312 additions and 340 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Check http://editorconfig.org for more information
# This is the main config file for this project:
root = true

[*]
charset = utf-8
trim_trailing_whitespace = true
end_of_line = lf
indent_style = space
insert_final_newline = true
indent_size = 2

[*.{rs,py,pyi}]
indent_size = 4

[*.snap]
trim_trailing_whitespace = false

[*.md]
max_line_length = 100
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto eol=lf
dist/** -diff linguist-generated=true
14 changes: 6 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# Keep GitHub Actions up to date with GitHub's Dependabot...
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#package-ecosystem
version: 2
updates:
- package-ecosystem: github-actions
directory: /
groups:
github-actions:
patterns:
- "*" # Group all Actions updates into a single larger pull request
schedule:
interval: weekly
interval: daily

- package-ecosystem: npm
directory: /
schedule:
interval: daily
16 changes: 0 additions & 16 deletions .github/workflows/actionlint.yml

This file was deleted.

49 changes: 49 additions & 0 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# `dist/index.js` is a special file in Actions.
# When you reference an action with `uses:` in a workflow,
# `index.js` is the code that will run.
# For our project, we generate this file through a build process from other source files.
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
name: Check dist/

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
check-dist:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm ci

- name: Rebuild the dist/ directory
run: |
npm run build
npm run package
- name: Compare the expected and actual dist/ directories
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff --text -v
exit 1
fi
id: diff

# If index.js was different than expected, upload the expected version as an artifact
- uses: actions/upload-artifact@v4
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: dist
path: dist/
71 changes: 71 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [main]
pull_request:
# The branches below must be a subset of the branches above
branches: [main]
schedule:
- cron: "31 7 * * 3"

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: ["TypeScript"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
source-root: src
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
16 changes: 0 additions & 16 deletions .github/workflows/python.yml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Release Drafter

# yamllint disable-line rule:truthy
on:
push:
branches:
- main
workflow_dispatch:

jobs:
update_release_draft:
name: ✏️ Draft release
runs-on: ubuntu-latest
steps:
- name: 🚀 Run Release Drafter
uses: release-drafter/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26 changes: 0 additions & 26 deletions .github/workflows/stale.yml

This file was deleted.

142 changes: 142 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: "test"
on:
pull_request:
workflow_dispatch:
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Actionlint
uses: eifinger/actionlint-action@bdc2a242a53ae50e609e29f8eeb0d05d792edc09 # v1.7.0
continue-on-error: true # Until https://github.com/rhysd/actionlint/pull/485 is released
- uses: actions/setup-node@v4
with:
node-version: "20"
- run: |
npm install
- run: |
npm run all
- name: Make sure no changes from linters are detected
run: |
git diff --exit-code
test-default-version:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, macos-14, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Use default version
uses: ./
with:
src: __tests__/fixtures/python-project
test-specific-version:
runs-on: ubuntu-latest
strategy:
matrix:
ruff-version: ["0.7.4", "0.7", "0.7.x", ">=0.7.0"]
steps:
- uses: actions/checkout@v4
- name: Use version ${{ matrix.ruff-version }}
uses: ./

Check failure on line 50 in .github/workflows/test.yml

View workflow job for this annotation

GitHub Actions / lint

incorrect color "black" at branding.icon in metadata of "ruff-action" action at "/home/runner/work/ruff-action/ruff-action/action.yml". see the official document to know the exhaustive list of supported colors: https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#brandingcolor
with:
version: ${{ matrix.ruff-version }}
src: __tests__/fixtures/python-project
test-semver-range:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use version 0.7
id: ruff-action
uses: ./
with:
version: "0.7"
src: __tests__/fixtures/python-project
- name: Correct version gets installed
run: |
if [ "$RUFF_VERSION" != "0.7.4" ]; then
exit 1
fi
env:
RUFF_VERSION: ${{ steps.ruff-action.outputs.ruff-version }}
test-checksum:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
checksum:
["0de731c669b9ece77e799ac3f4a160c30849752714d9775c94cc4cfaf326860c"]
exclude:
- os: macos-latest
checksum: "0de731c669b9ece77e799ac3f4a160c30849752714d9775c94cc4cfaf326860c"
include:
- os: macos-latest
checksum: "af9583bff12afbca5d5670334e0187dd60c4d91bc71317d1b2dde70cb1200ba9"
steps:
- uses: actions/checkout@v4
- name: Checksum matches expected
uses: ./
with:
version: "0.7.4"
checksum: ${{ matrix.checksum }}
src: __tests__/fixtures/python-project
test-with-explicit-token:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use default version
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
src: __tests__/fixtures/python-project
test-args:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Use args
uses: ./
with:
args: format --check
src: __tests__/fixtures/python-project
test-failure:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use args
id: should-fail
continue-on-error: true
uses: ./
with:
args: format --check
src: __tests__/fixtures/malformed-python-project
- name: Check if the action failed
run: |
if [ ${{ steps.should-fail.outcome }} == "success" ]; then
exit 1
fi
test-multiple-src:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, windows-latest ]
steps:
- uses: actions/checkout@v4
- name: Use args
uses: ./
with:
args: format --check
src: >-
__tests__/fixtures/python-project/src/python_project/__init__.py
__tests__/fixtures/python-project/src/python_project/hello_world.py
Loading

0 comments on commit f2e3221

Please sign in to comment.