From f52f4eb5382fcce3e2b61c77f42b2757c004c24d Mon Sep 17 00:00:00 2001 From: Louis Rose Date: Mon, 18 Mar 2024 11:53:12 +0000 Subject: [PATCH] adds build --- .github/workflows/preview.yaml | 20 +++++++++++ .github/workflows/release.yaml | 65 ++++++++++++++++++++++++++++++++++ .github/workflows/test.yaml | 22 ++++++++++++ Makefile | 8 ++--- 4 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/preview.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/preview.yaml b/.github/workflows/preview.yaml new file mode 100644 index 0000000..2151470 --- /dev/null +++ b/.github/workflows/preview.yaml @@ -0,0 +1,20 @@ +name: preview + +on: + pull_request: + types: + - labeled + +jobs: + release: + name: Preview release + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - id: bumpr + if: "!startsWith(github.ref, 'refs/tags/')" + name: Bump versions + uses: haya14busa/action-bumpr@v1 \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..bce0b14 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,65 @@ +name: release + +on: + push: + branches: + - main + +jobs: + release: + name: Release + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + # we have to use an administrator's personal access token to be able to push to a protected branch + # https://github.com/stefanzweifel/git-auto-commit-action?tab=readme-ov-file#push-to-protected-branches + token: ${{ secrets.PAT }} + + - id: bumpr-check + if: "!startsWith(github.ref, 'refs/tags/')" + name: Check for version bump + uses: haya14busa/action-bumpr@v1 + with: + dry_run: true + + - if: "!steps.bumpr-check.outputs.skip" + name: Bump version + run: | + VERSION=${{ steps.bumpr-check.outputs.next_version }} + VERSION=${VERSION#v} make bump + + - if: "!steps.bumpr-check.outputs.skip" + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "Bump version to ${{ steps.bumpr-check.outputs.next_version }}" + + - id: bumpr + if: "!startsWith(github.ref, 'refs/tags/')" + name: Perform version bump + uses: haya14busa/action-bumpr@v1 + + - if: "!steps.bumpr.outputs.skip" + name: Update tags + uses: haya14busa/action-update-semver@v1 + with: + github_token: ${{ secrets.github_token }} + tag: ${{ steps.bumpr.outputs.next_version }} + + - if: "!steps.bumpr.outputs.skip" + env: + MVN_CENTRAL_USERNAME: ${{ secrets.MVN_CENTRAL_USERNAME }} + MVN_CENTRAL_PASSWORD: ${{ secrets.MVN_CENTRAL_PASSWORD }} + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + name: Publish to Maven Central + run: make publish + + - if: "!steps.bumpr.outputs.skip" + name: Release + uses: softprops/action-gh-release@v1 + with: + generate_release_notes: true + tag_name: ${{ steps.bumpr.outputs.next_version }} \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..b38995a --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,22 @@ +name: test + +on: + pull_request + +jobs: + test: + name: Run tests + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build + run: make build + + - name: Run tests + run: make test \ No newline at end of file diff --git a/Makefile b/Makefile index 32dc982..6ee54e9 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ generate: up @$(eval VERSION=$(shell $(MVN_CMD) help:evaluate -Dexpression=project.version -q -DforceStdout)) @$(GENERATOR_CMD) $(GENERATE_ARGS) --additional-properties=artifactVersion=$(VERSION) -build: generate +build: up @$(MVN_CMD) clean test-compile test: build @@ -41,14 +41,14 @@ endif ifndef MVN_CENTRAL_PASSWORD $(error MVN_CENTRAL_PASSWORD is not set) endif -ifndef GPG_PRIVATE_KEY_PATH - $(error GPG_PRIVATE_KEY_PATH is not set) +ifndef GPG_PRIVATE_KEY + $(error GPG_PRIVATE_KEY is not set) endif ifndef GPG_PASSPHRASE $(error GPG_PASSPHRASE is not set) endif @docker compose exec maven mkdir -p /root/.m2 @docker compose exec maven sh -c 'echo "central$(MVN_CENTRAL_USERNAME)$(MVN_CENTRAL_PASSWORD)" > /root/.m2/settings.xml' - @docker compose cp $(GPG_PRIVATE_KEY_PATH) maven:/root/api-sdks.asc + @docker compose exec maven sh -c 'echo "$(GPG_PRIVATE_KEY)" > /root/api-sdks.asc' @docker compose exec maven gpg --batch --import --pinentry-mode loopback --passphrase "$(GPG_PASSPHRASE)" /root/api-sdks.asc @$(MVN_CMD) deploy -DskipTests -Dgpg.keyname=api-sdks -Dgpg.passphrase=$(GPG_PASSPHRASE) \ No newline at end of file