diff --git a/.github/workflows/pull-request-build.yml b/.github/workflows/pull-request-build.yml index 3eec8bb..aec096e 100644 --- a/.github/workflows/pull-request-build.yml +++ b/.github/workflows/pull-request-build.yml @@ -18,5 +18,8 @@ jobs: run: git merge origin/master - name: Build Docker Image id: build_docker_image - run: make docker-build - + run: | + make \ + GITHUB_HEAD_REF=${GITHUB_HEAD_REF:-${GITHUB_REF##*/}} \ + GITHUB_EVENT_NAME=${GITHUB_EVENT_NAME} \ + docker-build diff --git a/.github/workflows/push-build.yml b/.github/workflows/push-build.yml index e91fbff..247b5b9 100644 --- a/.github/workflows/push-build.yml +++ b/.github/workflows/push-build.yml @@ -16,4 +16,8 @@ jobs: run: git checkout origin/${GITHUB_HEAD_REF:-${GITHUB_REF##*/}} - name: Build Docker Image id: build_docker_image - run: make docker-build \ No newline at end of file + run: | + make \ + GITHUB_HEAD_REF=${GITHUB_HEAD_REF:-${GITHUB_REF##*/}} \ + GITHUB_EVENT_NAME=${GITHUB_EVENT_NAME} \ + docker-build \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index fb928c1..4a1833d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added to 1.1.0 - Ability to attach files to the Jira Issue -- Update make file so it can be used both by the Git Actions pipeline and directly - Docker file to include the default Git Actions workspace so it can be leveraged to interact with the runner's workspace during a CI/CD pipeline. ## [1.0.0] - 2020-01-11 diff --git a/Makefile b/Makefile index 6b29285..af6c350 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ GIT_REPOSITORY_NAME := $(shell basename `git rev-parse --show-toplevel`) GIT_VERSION := $(shell git describe --always --tags --long --dirty | sed -e 's/\-0//' -e 's/\-g.......//') +GITHUB_HEAD_REF ?= "master" +GITHUB_EVENT_NAME ?= "push" # ----------------------------------------------------------------------------- # Functions @@ -32,43 +34,27 @@ build: fmt .PHONY: default default: help -# ----------------------------------------------------------------------------- -# Copy files to docker build folder -# ----------------------------------------------------------------------------- -.PHONY: copy-docker-files -copy-docker-files: - @mkdir -p build/docker/$(GIT_REPOSITORY_NAME) - @cp Makefile LICENSE README.md main.go go.mod go.sum build/docker/$(GIT_REPOSITORY_NAME) - @cp -r configuration build/docker/$(GIT_REPOSITORY_NAME) - -.PHONY: delete-docker-files -delete-docker-files: - @rm -rf build/docker/$(GIT_REPOSITORY_NAME) - # ----------------------------------------------------------------------------- # Docker-based build # ----------------------------------------------------------------------------- -.PHONY: docker -docker: docker-rmi-for-build +.PHONY: docker-build +docker-build: docker-rmi-for-build docker build \ + --build-arg GITHUB_HEAD_REF=$(GITHUB_HEAD_REF) \ + --build-arg GITHUB_EVENT_NAME=$(GITHUB_EVENT_NAME) \ --tag $(GIT_REPOSITORY_NAME) \ --tag $(GIT_REPOSITORY_NAME):$(GIT_VERSION) \ - --build-arg GO_BUILD_FILES=$(GIT_REPOSITORY_NAME) \ build/docker -.PHONY: docker-development-cache -docker-development-cache: docker-rmi-for-build-development-cache +.PHONY: docker-build-development-cache +docker-build-development-cache: docker-rmi-for-build-development-cache docker build \ + --build-arg GITHUB_HEAD_REF=$(GITHUB_HEAD_REF) \ + --build-arg GITHUB_EVENT_NAME=$(GITHUB_EVENT_NAME) \ --tag $(GIT_REPOSITORY_NAME):$(GIT_VERSION) \ build/docker -.PHONY: docker-build -docker-build: copy-docker-files docker delete-docker-files - -.PHONY: docker-build-development-cache -docker-build-development-cache: copy-docker-files docker-development-cache delete-docker-files - # ----------------------------------------------------------------------------- # Clean up targets # ----------------------------------------------------------------------------- diff --git a/build/docker/Dockerfile b/build/docker/Dockerfile index 8f0a2a1..fc2265c 100644 --- a/build/docker/Dockerfile +++ b/build/docker/Dockerfile @@ -3,7 +3,8 @@ # ----------------------------------------------------------------------------- FROM golang:1.13.4-alpine3.10 as BUILD -ARG GO_BUILD_FILES=git-action-jira-issue-creation +ARG GITHUB_HEAD_REF="master" +ARG GITHUB_EVENT_NAME="push" # Add github RUN apk update && \ @@ -12,10 +13,19 @@ RUN apk update && \ git \ make -# Copy repo -COPY ${GO_BUILD_FILES} /go/src/${GO_BUILD_FILES} +WORKDIR /go/src -WORKDIR /go/src/${GO_BUILD_FILES} +# Clone repo +RUN git clone https://github.com/senzing/git-action-jira-issue-creation.git + +WORKDIR /go/src/git-action-jira-issue-creation + +# Check merge if build is triggered by a pull request +WORKDIR /go/src/git-action-jira-issue-creation +RUN if [[ "${GITHUB_HEAD_REF}" != "master" && "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then \ + git checkout ${GITHUB_HEAD_REF}; \ + git merge master; \ + fi # Building go app RUN make build