Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite for usage primarily on GitHub Actions #235

Merged
merged 17 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 40 additions & 61 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
- uses: actions/checkout@v4
- id: stack
uses: freckle/stack-action@v5
- uses: freckle/weeder-action@v2
with:
ghc-version: ${{ steps.stack.outputs.compiler-version }}
# - uses: freckle/weeder-action@v2
# with:
# ghc-version: ${{ steps.stack.outputs.compiler-version }}
- run: |
dist=restyler-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)
mkdir -p "$dist"
Expand All @@ -48,70 +48,49 @@ jobs:
with:
fail-on: warning

image:
test-action:
needs: build
runs-on: ubuntu-latest
steps:
- id: meta
uses: docker/metadata-action@v5
with:
images: restyled/restyler
tags: |
type=sha,prefix=,priority=1000
type=edge,branch=main
type=ref,event=tag

- uses: docker/setup-buildx-action@v3

- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- uses: docker/build-push-action@v5
with:
cache-from: type=gha
cache-to: type=gha,mode=max
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

outputs:
tags: ${{ steps.meta.outputs.tags }}
- uses: actions/download-artifact@v4
name: linux-binaries
- run: |
tar xzf linux-binaries/restyler-*.tar.gz
mv -v restyler-*/restyle-gha /usr/local/bin
rm -rf linux-binaries
- uses: actions/checkout@v4
- uses: ./actions/run

deploy:
if: ${{ github.ref == 'refs/heads/main' }}
image:
runs-on: ubuntu-latest

needs: [build, image]

steps:
- name: setup
run: |
cat > ~/.netrc <<EOF
machine api.heroku.com
login $HEROKU_EMAIL
password $HEROKU_API_KEY
machine git.heroku.com
login $HEROKU_EMAIL
password $HEROKU_API_KEY
EOF
env:
HEROKU_EMAIL: ${{ secrets.HEROKU_EMAIL }}
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}

- name: deploy
run: |
read -r tag <<'EOM'
${{ needs.image.outputs.tags }}
EOM
heroku config:set --app restyled-io "RESTYLER_IMAGE=$tag"
- run: echo "Skipping this for now"
# - id: meta
# uses: docker/metadata-action@v5
# with:
# images: restyled/restyler
# tags: |
# type=sha,prefix=,priority=1000
# type=edge,branch=main
# type=ref,event=tag

# - uses: docker/setup-buildx-action@v3

# - uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_PASSWORD }}

# - uses: docker/build-push-action@v5
# with:
# cache-from: type=gha
# cache-to: type=gha,mode=max
# push: ${{ github.event_name != 'pull_request' }}
# tags: ${{ steps.meta.outputs.tags }}
# labels: ${{ steps.meta.outputs.labels }}

- uses: desiderati/github-action-pushover@v1
if: ${{ always() }}
with:
job-status: ${{ job.status }}
pushover-api-token: ${{ secrets.PUSHOVER_API_TOKEN }}
pushover-user-key: ${{ secrets.PUSHOVER_USER_KEY }}
outputs:
tags: ${{ steps.meta.outputs.tags }}

release:
if: ${{ github.ref == 'refs/heads/main' }}
Expand Down
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@ The restyling process, as a CLI.

## Usage

### GitHub Actions

```yaml
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- uses: restyled-io/restyler/actions/setup@v1
- uses: restyled-io/restyler/actions/run@v1
```

### Locally

```console
docker run --rm \
--env "GITHUB_ACCESS_TOKEN=<access-token>" \
--volume /tmp:tmp \
--volume /var/run/docker.sock:/var/run/docker.sock \
restyled/restyler "<owner>/<name>#<number>"
curl --proto '=https' --tlsv1.2 -sSf \
https://raw.githubusercontent.com/restyled-io/restyler/main/install | sudo sh
```

**NOTE**: The Access Token you use will determine some of the resulting
behavior. In production, we use a token provisioned for an installed instance of
our GitHub App, which ensures the restyled PRs and comments appear as authored
by our App. If you use a Personal Access Token, the restyled PRs and comments
will be authored by your user.
```console
restyle --help
```

## Development

Expand All @@ -40,10 +47,6 @@ End-to-end test that restyles an example Pull Request:
just test-integration
```

## `restyle-path`

See [bin/restyle-path](./bin/restyle-path).

## LICENSE

Restyled is source-available, [Commons Claused][cc] licensed. For a detailed
Expand Down
60 changes: 60 additions & 0 deletions actions/run/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Restyler
author: pbrisbin

inputs:
log-breakpoint:
description: "LOG_BREAKPOINT"
default: 200
log-color:
description: "LOG_COLOR"
default: always
log-format:
description: "LOG_FORMAT"
default: tty
log-level:
description: "LOG_LEVEL"
default: "info"
github-token:
description: "GITHUB_TOKEN"
default: ${{ github.token }}
committer-email:
description: "Email used for Restyled commits"
default: "[email protected]"
committer-name:
description: "Name used for Restyled commits"
default: "Restyled.io"

outputs:
differences:
value: ${{ steps.restyler.outputs.differences }}
restyled-base:
value: ${{ steps.restyler.outputs.restyled-base }}
restyled-head:
value: ${{ steps.restyler.outputs.restyled-head }}
restyled-title:
value: ${{ steps.restyler.outputs.restyled-title }}
restyled-body:
value: ${{ steps.restyler.outputs.restyled-body }}
restyled-labels:
value: ${{ steps.restyler.outputs.restyled-labels }}
restyled-reviewers:
value: ${{ steps.restyler.outputs.restyled-reviewers }}
restyled-team-reviewers:
value: ${{ steps.restyler.outputs.restyled-team-reviewers }}

runs:
using: composite
steps:
- id: restyler
shell: bash
run: restyle-gha --pr '${{github.repository }}#${{ github.event.pull_request.number }}'
env:
GITHUB_TOKEN: ${{ github.token }}
GIT_AUTHOR_EMAIL: ${{ inputs.committer-email }}
GIT_AUTHOR_NAME: ${{ inputs.committer-name }}
GIT_COMMITTER_EMAIL: ${{ inputs.committer-email }}
GIT_COMMITTER_NAME: ${{ inputs.committer-name }}
LOG_BREAKPOINT: ${{ inputs.log-breakpoint }}
LOG_COLOR: ${{ inputs.log-color }}
LOG_FORMAT: ${{ inputs.log-format }}
LOG_LEVEL: ${{ inputs.log-level }}
14 changes: 14 additions & 0 deletions app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Main
( main
) where

import Restyler.Prelude

import Restyler.CLI qualified as CLI
import Restyler.Local
import Restyler.Local.App

main :: IO ()
main = CLI.main withApp $ do
paths <- asks (.paths)
run NullPullRequest $ toList paths
33 changes: 0 additions & 33 deletions app/main.hs

This file was deleted.

52 changes: 0 additions & 52 deletions bin/clone-test

This file was deleted.

11 changes: 0 additions & 11 deletions bin/clone-tests

This file was deleted.

Loading