diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c62ffae0..867a184f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,13 @@ name: release on: - push: - tags: - - v** + workflow_dispatch: + # Inputs the workflow accepts. + inputs: + tag: + # Friendly description to be shown in the UI instead of 'name' + description: 'tag and release to create' + # Input has to be provided for the workflow to run + required: true env: GITHUB_ENV: ".env" jobs: @@ -15,13 +20,33 @@ jobs: go-version: ^1.27 - name: Check out code into the Go module directory uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: Validate that the release manifest exists - run: | - [[ -f "releases/do-operator-$(git describe --tags).yaml" ]] || false - name: Login to dockerhub to push the image - run: echo "${{ secrets.DockerHubToken }}" | docker login --username ${DOCKER_USER} --password-stdin + run: echo "${{ secrets.DockerHubToken }}" | docker login --username "${DOCKER_USER}" --password-stdin env: DOCKER_USER: ${{ secrets.DockerHubUser }} - - name: Build and push docker image + - name: run make release ${{ github.event.inputs.tag }} + run: make release + env: + IMG_TAG: ${{ github.event.inputs.tag }} + - name: commit manifests + uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5 # v9.1.4 + with: + message: "create release manifests for ${{ github.event.inputs.tag }}" + # Also pin the controller image tag in config/manager (release-manifests runs kustomize edit). + add: "releases/ config/manager/kustomization.yaml" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # target commit should be the commit with the new release manifest, not the commit when workflow was triggered + - name: find target commit to tag run: | - make docker-build docker-push IMG_TAG="$(git describe --tags)" + sha="$(git rev-parse HEAD)" + echo "TARGET_SHA=${sha}" >> "${GITHUB_ENV}" + - name: Create Release + id: create_release + uses: actions/create-release@0cb9c9b65d5d1901c1f53e5e66eaf4afd303e70e # v1.1.4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + commitish: ${{ env.TARGET_SHA }} + tag_name: ${{ github.event.inputs.tag }} + release_name: Release ${{ github.event.inputs.tag }} diff --git a/Makefile b/Makefile index ac9e1a2b..48409aca 100644 --- a/Makefile +++ b/Makefile @@ -113,6 +113,9 @@ release-manifests: manifests kustomize # replace the fake do api token cause GitGuardian thinks every base64-encoded string is a secret sed -i -e 's/access-token\:\s.*/access-token: /g' releases/do-operator-${IMG_TAG}.yaml +.PHONY: release +release: docker-build docker-push release-manifests ## Build/push image and generate release manifests for IMG_TAG + ##@ Build Dependencies ## Location to install dependencies to diff --git a/README.md b/README.md index c6814c93..d50b9388 100644 --- a/README.md +++ b/README.md @@ -130,12 +130,19 @@ make uninstall 4. Create and merge PR ### Release -1. Create release manifest files by running `GITHUB_TOKEN= IMG_TAG=vX.Y.Z make release-manifests` -2. Create and merge PR -3. [Trigger the `release` GitHub action workflow](https://github.com/digitalocean/do-operator/actions/workflows/release.yml) - - Draft a new release [here](https://github.com/digitalocean/do-operator/releases) for the new version - - Creating a new release will trigger the [release](https://github.com/digitalocean/do-operator/actions/workflows/release.yml) Github Action - - Follow the [release](https://github.com/digitalocean/do-operator/actions/workflows/release.yml) Github Action until successful completion. + +To create the docker image and generate the manifests, go to the actions page on Github and click on `Run Workflow` . +Specify the github tag that you want to create. Running the workflow also requires that you temporarily turn off "Require a pull request before merging" setting in the main [branch protection rules settings](https://github.com/digitalocean/do-operator/settings/branches). Don't forget to turn it back on once the release is done! + +The workflow does the following: + +- Login with dockerhub credentials specified as secrets +- Builds the docker image `digitalocean/do-operator:` +- Pushes `digitalocean/do-operator:` to dockerhub +- Creates the do-operator related manifest file as `do-operator-.yaml` +- Updates `config/manager/kustomization.yaml` with the release image tag +- Commits the manifest file under releases/ directory in the repo +- Creates release and tags the new commit with the input `tag` specified when workflow is triggered ## Contributing