diff --git a/.github/workflows/buildpush.yml b/.github/workflows/release.yml similarity index 50% rename from .github/workflows/buildpush.yml rename to .github/workflows/release.yml index 7e82015..5f0bf9d 100644 --- a/.github/workflows/buildpush.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,7 @@ # separate terms of service, privacy policy, and support # documentation. -name: Create and publish a Docker image +name: Build and release the controller image on: push: @@ -11,18 +11,29 @@ on: env: REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} + IMAGE: ghcr.io/${{ github.repository }} jobs: - build-and-push-image: + build-and-release: runs-on: ubuntu-latest permissions: - contents: read + issues: read + contents: write packages: write steps: - - name: Checkout repository - uses: actions/checkout@v2 + + - name: setup node + uses: actions/setup-node@v1 + with: + node-version: 12 + registry-url: https://registry.npmjs.org/ + + - name: setup release tools + run: npm install -g semantic-release@15 @semantic-release/exec + + - name: Install make + run: sudo apt-get install -y make - name: Log in to the Container registry uses: docker/login-action@v1 @@ -31,9 +42,11 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push Docker image - uses: docker/build-push-action@v2 - with: - context: . - push: true - tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Push and release image + run: npx semantic-release + env: + IMAGE: ${{ env.IMAGE }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 30eafff..4d34982 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,9 @@ name: Test on: push: - branches: + branches-ignore: + - 'release' + tags-ignore: - '*' pull_request: {} diff --git a/.releaserc b/.releaserc new file mode 100644 index 0000000..4cbf9f5 --- /dev/null +++ b/.releaserc @@ -0,0 +1,15 @@ +{ + "branch": "release", + "plugins": [ + "@semantic-release/commit-analyzer", + ["@semantic-release/release-notes-generator", { + "writerOpts": { + "headerPartial": "# {{version}}\nImage: `ghcr.io/inovex/aws-auth-controller:{{version}}`" + } + }], + ["@semantic-release/exec", { + "publishCmd": "make release version=${nextRelease.version}" + }], + "@semantic-release/github" + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile index 2c9255f..e668957 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ # Image URL to use all building/pushing image targets -IMG ?= controller:latest +version ?= test +IMAGE ?= controller +IMG ?= ${IMAGE}:${version} # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false" @@ -60,12 +62,16 @@ build: generate fmt vet ## Build manager binary. run: manifests generate fmt vet ## Run a controller from your host. go run ./main.go -docker-build: test ## Build docker image with the manager. +docker-build: ## Build docker image with the manager. docker build -t ${IMG} . docker-push: ## Push docker image with the manager. docker push ${IMG} +##@ Release + +release: docker-build docker-push + ##@ Deployment install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.