Skip to content

Commit

Permalink
Check input directory for empty repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
emcfarlane committed Aug 2, 2024
1 parent 0d29f75 commit 2bec266
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 2 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ jobs:
with:
setup_only: true
- run: buf --version | grep $BUF_VERSION
test-empty-build:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- uses: ./
with:
lint: false
format: false
breaking: false
push: false
archive: false
pr_comment: false
continue-on-error: true # build fails
test-lint:
runs-on: ubuntu-latest
needs: build
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/draft-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Prepare Release
on:
workflow_dispatch:
inputs:
version:
type: string
description: The released CLI version without 'v'. For example, 1.0.0.
permissions:
contents: write
env:
APP_ID: 257262
jobs:
draft_release:
runs-on: ubuntu-latest
steps:
- name: Validate input version
if: ${{ startsWith(github.event.inputs.version, 'v') }}
run: |
echo "error: version must not start with 'v'."
exit 1
- name: Set VERSION variable
# The head ref looks like release/v1.0.0, and we need to trim the string up to the `/v`.
run: |
VERSION="${{ github.event.inputs.version || github.head_ref}}"
echo "VERSION=${VERSION##*/v}" >> $GITHUB_ENV
- name: Get GitHub app token
uses: actions/create-github-app-token@v1
id: app_token
with:
app-id: ${{ env.APP_ID }}
private-key: ${{ secrets.TOKEN_EXCHANGE_GH_APP_PRIVATE_KEY }}
- name: Checkout repository code
uses: actions/checkout@v3
with:
token: ${{ steps.app_token.outputs.token }}
fetch-depth: 0
- name: Sync v1 branch
run: |
git fetch origin
git switch v1
git merge origin/main
git push origin v1
- name: Release
run: gh release create --draft --title "v${VERSION}" "v${VERSION}"
env:
GH_TOKEN: ${{ steps.app_token.outputs.token }}
49 changes: 49 additions & 0 deletions .github/workflows/prepare-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Draft Release
on:
pull_request:
types: [closed]
workflow_dispatch:
inputs:
version:
type: string
description: The released CLI version without 'v'. For example, 1.0.0.
permissions:
contents: write
env:
APP_ID: 257262
jobs:
draft_release:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release')) }}
steps:
- name: Validate input version
if: ${{ startsWith(github.event.inputs.version, 'v') }}
run: |
echo "error: version must not start with 'v'."
exit 1
- name: Set VERSION variable
# The head ref looks like release/v1.0.0, and we need to trim the string up to the `/v`.
run: |
VERSION="${{ github.event.inputs.version || github.head_ref}}"
echo "VERSION=${VERSION##*/v}" >> $GITHUB_ENV
- name: Get GitHub app token
uses: actions/create-github-app-token@v1
id: app_token
with:
app-id: ${{ env.APP_ID }}
private-key: ${{ secrets.TOKEN_EXCHANGE_GH_APP_PRIVATE_KEY }}
- name: Checkout repository code
uses: actions/checkout@v3
with:
token: ${{ steps.app_token.outputs.token }}
fetch-depth: 0
- name: Sync v1 branch
run: |
git fetch origin
git switch v1
git merge origin/main
git push origin v1
- name: Release
run: gh release create --draft --title "v${VERSION}" "v${VERSION}"
env:
GH_TOKEN: ${{ steps.app_token.outputs.token }}
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ jobs:
buf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/buf-action@v1
- name: Checkout code
uses: actions/checkout@v4
- name: Run Buf
uses: bufbuild/buf-action@v1
with:
token: ${{ secrets.BUF_TOKEN }}
```
Expand Down
4 changes: 4 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45828,6 +45828,10 @@ async function runWorkflow(bufPath, inputs, moduleNames) {
const steps = {};
steps.build = await build(bufPath, inputs);
if (steps.build.status == Status.Failed) {
if (steps.build.stderr.match(/had no .proto files/)) {
core.info("Empty repository detected, ensure the repository is checked out");
return steps;
}
return steps;
}
const checks = await Promise.all([
Expand Down
6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ async function runWorkflow(
const steps: Steps = {};
steps.build = await build(bufPath, inputs);
if (steps.build.status == Status.Failed) {
if (steps.build.stderr.match(/had no .proto files/)) {
core.info(
"Empty repository detected, ensure the repository is checked out",
);
return steps;
}
return steps;
}
const checks = await Promise.all([
Expand Down

0 comments on commit 2bec266

Please sign in to comment.