From 676228e6a171fb859b104b15b84bde16dfe4414d Mon Sep 17 00:00:00 2001 From: Luke Hagar Date: Tue, 1 Oct 2024 15:22:07 +0000 Subject: [PATCH] adding action --- .github/workflows/release.yaml | 118 +++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..8ae437a --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,118 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + +permissions: + contents: write + packages: write + pull-requests: write + +env: + GO_VERSION: 1.21.3 + APP_NAME: theschemagen + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + + - name: Setup Go + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install Dependencies + run: go mod download + + - name: Verify Dependencies + run: go mod verify + + - name: Lint ${{ env.APP_NAME }} + run: go vet ./... + + test: + name: Test + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + + - name: Setup Go + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install Dependencies + run: go mod download + + - name: Verify Dependencies + run: go mod verify + + - name: Test ${{ env.APP_NAME }} + run: go test -v ./... + + changelog: + name: Changelog + needs: + - lint + - test + if: github.event_name != 'pull_request' + runs-on: ubuntu-latest + + outputs: + skipped: ${{ steps.changelog.outputs.skipped }} + tag: ${{ steps.changelog.outputs.tag }} + clean_changelog: ${{ steps.changelog.outputs.clean_changelog }} + version: ${{ steps.changelog.outputs.version }} + + env: + PR_BRANCH: release-ci-${{ github.sha }} + + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + - name: Create Branch + run: | + git checkout -b ${{ env.PR_BRANCH }} + + - name: Create Changelog + uses: TriPSs/conventional-changelog-action@dd734f74fce61a6e02f821ee1b5930bc79a23534 # v5 + id: changelog + with: + github-token: ${{ github.token }} + git-user-name: "github-actions[bot]" + git-user-email: "github-actions[bot]@users.noreply.github.com" + git-branch: ${{ env.PR_BRANCH }} + skip-git-pull: true + output-file: false + version-file: .github/package.yaml + create-summary: true + + - name: Create Changelog PR + if: steps.changelog.outputs.skipped == 'false' + run: | + gh pr create --base main --head ${{ env.PR_BRANCH }} --title 'chore(release): ${{ steps.changelog.outputs.tag }} [skip-ci]' --body '${{ steps.changelog.outputs.clean_changelog }}' + env: + GH_TOKEN: ${{ github.token }} + + - name: Approve Changelog PR + if: steps.changelog.outputs.skipped == 'false' + run: | + gh pr review --approve ${{ env.PR_BRANCH }} + env: + GH_TOKEN: ${{ secrets.GH_OWNER_TOKEN }} + + - name: Merge Changelog PR + if: steps.changelog.outputs.skipped == 'false' + run: | + gh pr merge --squash --auto --delete-branch ${{ env.PR_BRANCH }} + env: + GH_TOKEN: ${{ secrets.GH_OWNER_TOKEN }}