diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1b15ce4..eeda9d5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/.github/workflows/draft-release.yaml b/.github/workflows/draft-release.yaml new file mode 100644 index 0000000..b3e7d05 --- /dev/null +++ b/.github/workflows/draft-release.yaml @@ -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 }} diff --git a/.github/workflows/prepare-release.yaml b/.github/workflows/prepare-release.yaml new file mode 100644 index 0000000..e948bd9 --- /dev/null +++ b/.github/workflows/prepare-release.yaml @@ -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 }} diff --git a/README.md b/README.md index 7c7d9d6..26e4cca 100644 --- a/README.md +++ b/README.md @@ -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 }} ``` diff --git a/dist/index.js b/dist/index.js index 2592202..6598321 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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([ diff --git a/src/main.ts b/src/main.ts index d0d3ddf..a309369 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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([