From d682a7a5a8789acdc149e5fe93b10fa953b09494 Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Sun, 29 Dec 2024 11:26:17 +0000 Subject: [PATCH] Update action to use prebuilt Docker image Update the action to use a prebuilt Docker image and add workflows for continuous delivery and version checking. * **action.yml** - Update the `runs` section to use `ghcr.io/launchdarkly/find-code-references-in-pull-request:latest` as the prebuilt Docker image. * **.github/workflows/main.yml** - Update the `Find LaunchDarkly feature flags in diff` step to use the prebuilt Docker image `ghcr.io/launchdarkly/find-code-references-in-pull-request:latest`. * **.github/workflows/cd.yml** - Add a new workflow to build and publish the Docker image based on the example from `container-prebuilt-action`. * **.github/workflows/version-check.yml** - Add a new workflow to check the version of the Docker image based on the example from `container-prebuilt-action`. * **Dockerfile** - Delete the Dockerfile as it is no longer needed. --- .github/workflows/cd.yml | 61 +++++++++++++++++++++++++++++ .github/workflows/main.yml | 2 +- .github/workflows/version-check.yml | 39 ++++++++++++++++++ Dockerfile | 18 --------- action.yml | 2 +- 5 files changed, 102 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/cd.yml create mode 100644 .github/workflows/version-check.yml delete mode 100644 Dockerfile diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 00000000..6108edbe --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,61 @@ +# When a PR is merged, or when run manually, this workflow will create a +# release and publish the container image to the GitHub Container Registry. Both +# will be labeled with the version specified in the manifest file. +name: Continuous Delivery + +on: + pull_request: + types: + - closed + branches: + - main + workflow_dispatch: + +env: + CONTAINER_REGISTRY: ghcr.io + CONTAINER_REGISTRY_USERNAME: ${{ github.actor }} + CONTAINER_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }} + MANIFEST_PATH: action.yml + +permissions: + contents: write + packages: write + +jobs: + build: + name: Build and Publish + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.CONTAINER_REGISTRY }} + username: ${{ env.CONTAINER_REGISTRY_USERNAME }} + password: ${{ env.CONTAINER_REGISTRY_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.CONTAINER_REGISTRY }}/${{ github.repository }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Create Release + id: release + uses: issue-ops/releaser@v2 + with: + tag: v${{ steps.meta.outputs.version }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 39c11932..f8dafbbd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -75,7 +75,7 @@ jobs: - name: Checkout uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - name: Find LaunchDarkly feature flags in diff - uses: ./ # Uses an action in the root directory + uses: ghcr.io/launchdarkly/find-code-references-in-pull-request:latest # P4078 id: find-flags with: project-key: demo-dan-042021-2 diff --git a/.github/workflows/version-check.yml b/.github/workflows/version-check.yml new file mode 100644 index 00000000..6a1eb670 --- /dev/null +++ b/.github/workflows/version-check.yml @@ -0,0 +1,39 @@ +# This workflow checks the version of the container image that is being built +# in the current pull request. If the version has already been published, the +# workflow fails to prevent PRs from being merged until the version has been +# incremented in the manifest file. +name: Version Check + +on: + pull_request: + branches: + - main + +env: + MANIFEST_PATH: action.yml + +permissions: + checks: write + contents: read + pull-requests: write + +jobs: + check-version: + name: Version Check + runs-on: ubuntu-latest + + if: ${{ github.actor != 'dependabot[bot]' }} + + steps: + - name: Checkout + id: checkout + uses: actions/checkout@v4 + with: + fetch-tags: true + + - name: Check Version + id: check-version + uses: issue-ops/semver@v2 + with: + check-only: true + manifest-path: ${{ env.MANIFEST_PATH }} diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 2fe693fa..00000000 --- a/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM golang:alpine -LABEL com.github.actions.name="LaunchDarkly Find Flags" -LABEL com.github.actions.description="Flags" -LABEL homepage="https://www.launchdarkly.com" - -RUN apk update -RUN apk add --no-cache git - -RUN mkdir /app -WORKDIR /app -COPY . . -ENV GO111MODULE=on -RUN go mod download -RUN go build . - - - -ENTRYPOINT ["/app/find-code-references-in-pull-request"] diff --git a/action.yml b/action.yml index 15dca12c..99081bdb 100644 --- a/action.yml +++ b/action.yml @@ -3,7 +3,7 @@ name: 'LaunchDarkly Code References in Pull Request' description: 'Find references to feature flags in your pull request' runs: using: 'docker' - image: 'Dockerfile' + image: 'ghcr.io/launchdarkly/find-code-references-in-pull-request:latest' env: LD_PROJ_KEY: ${{ inputs.project-key }} LD_ACCESS_TOKEN: ${{ inputs.access-token }}