numtide/clean-git-action #1075
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
push: | |
branches: [main] | |
pull_request: | |
permissions: | |
contents: write | |
pull-requests: write | |
env: | |
RUST_BACKTRACE: 1 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
outputs: | |
output_dir: ${{ steps.get_output_dir.outputs.output_dir }} | |
steps: | |
- uses: actions/checkout@v3 | |
- run: rustup update | |
- id: get-rust-version | |
run: echo "rust_version=$(rustc --version)" >> $GITHUB_OUTPUT | |
shell: bash | |
- uses: actions/cache@v3 | |
with: | |
path: | | |
.bin/ | |
target/ | |
~/.cargo/ | |
key: ${{ runner.os }}_${{ steps.get-rust-version.outputs.rust_version }}_${{ hashFiles('rust-toolchain.toml', 'Cargo.toml', 'Cargo.lock') }} | |
restore-keys: | | |
${{ runner.os }}_${{ steps.get-rust-version.outputs.rust_version }}_ | |
${{ runner.os }}_ | |
- run: npm ci | |
- run: ./git_hooks/pre-commit | |
- run: cargo run build | |
- uses: numtide/clean-git-action@v2 | |
- id: get_output_dir | |
run: echo "output_dir=$(cargo run -- print-output-dir)" >> $GITHUB_OUTPUT | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: build_output_dir | |
path: ${{ steps.get_output_dir.outputs.output_dir }} | |
deploy-preview: | |
if: github.event_name == 'pull_request' | |
needs: build | |
environment: pull_request_deployment | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/download-artifact@v3 | |
with: | |
name: build_output_dir | |
path: ${{ needs.build.outputs.output_dir }} | |
- id: deploy | |
run: | | |
npx vercel pull --yes --environment=preview --scope mobusoperandi --token=${{ secrets.VERCEL_TOKEN }} | |
URL=$(npx vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}) | |
echo "URL=$URL" >> $GITHUB_OUTPUT | |
- uses: thollander/actions-comment-pull-request@v2 | |
with: | |
message: | | |
Branch deployed for review at: | |
${{ steps.deploy.outputs.URL }} | |
deploy-production: | |
if: github.ref == 'refs/heads/main' | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/download-artifact@v3 | |
with: | |
name: build_output_dir | |
path: ${{ needs.build.outputs.output_dir }} | |
- uses: JamesIves/github-pages-deploy-action@v4 | |
with: | |
folder: ${{ needs.build.outputs.output_dir }} |