diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 618a74a..5d41b98 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -19,13 +19,3 @@ updates: - ChristophShyper labels: - automatic - -# # Enable version updates for pip -# - package-ecosystem: pip -# directory: "/" -# schedule: -# interval: daily -# assignees: -# - ChristophShyper -# labels: -# - automatic diff --git a/.github/workflows/CRON.yml b/.github/workflows/CRON.yml index 4f56baf..2871e9e 100644 --- a/.github/workflows/CRON.yml +++ b/.github/workflows/CRON.yml @@ -7,15 +7,27 @@ on: jobs: build_and_push: - name: Build and push images - runs-on: ubuntu-latest + name: Build & push + runs-on: ubuntu-24.04-arm steps: - - name: Checkout repository + - name: Checkout uses: actions/checkout@v4 - - name: Build Docker image and push to registry + - name: Docker Buildx + uses: docker/setup-buildx-action@v3.9.0 + with: + install: true + + - name: QEMU + uses: docker/setup-qemu-action@v3.4.0 + with: + image: tonistiigi/binfmt:latest + platforms: amd64,arm64 + + - name: Build & push env: + DOCKER_BUILDKIT: 1 DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TERM: xterm-256color - run: make build + run: make push VERSION_PREFIX=test- diff --git a/.github/workflows/PUSH-MASTER.yml b/.github/workflows/PUSH-MASTER.yml index f16679f..0c13ccc 100644 --- a/.github/workflows/PUSH-MASTER.yml +++ b/.github/workflows/PUSH-MASTER.yml @@ -7,10 +7,10 @@ on: jobs: labels: - name: Update repo labels - runs-on: ubuntu-latest + name: Repo labels + runs-on: ubuntu-24.04-arm steps: - - name: Checkout repository + - name: Checkout uses: actions/checkout@v4 - name: Download labels' config @@ -26,33 +26,40 @@ jobs: yaml-file: .tmp/labels.yml lint: - name: Run linters - runs-on: ubuntu-latest + name: Linters + runs-on: ubuntu-24.04-arm steps: - - name: Checkout repository + - name: Checkout uses: actions/checkout@v4 - - name: Docker Lint - uses: luke142367/Docker-Lint-Action@v1.1.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Haskell Dockerfile Linter (Hadolint) - uses: brpaz/hadolint-action@v1.5.0 + - name: Hadolint + uses: hadolint/hadolint-action@v3.1.0 with: dockerfile: Dockerfile build_and_push: - name: Build and push images + name: Build & push needs: lint - runs-on: ubuntu-latest + runs-on: ubuntu-24.04-arm steps: - - name: Checkout repository + - name: Checkout uses: actions/checkout@v4 - - name: Build Docker image and push to registry + - name: Docker Buildx + uses: docker/setup-buildx-action@v3.9.0 + with: + install: true + + - name: QEMU + uses: docker/setup-qemu-action@v3.4.0 + with: + image: tonistiigi/binfmt:latest + platforms: amd64,arm64 + + - name: Build & push env: + DOCKER_BUILDKIT: 1 DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TERM: xterm-256color - run: make build push + run: make push diff --git a/.github/workflows/PUSH-OTHER.yml b/.github/workflows/PUSH-OTHER.yml index 79a635c..f74b5e8 100644 --- a/.github/workflows/PUSH-OTHER.yml +++ b/.github/workflows/PUSH-OTHER.yml @@ -4,23 +4,22 @@ on: push: branches-ignore: - master - - release/* jobs: labels: - name: Update repo labels - runs-on: ubuntu-latest + name: Repo labels + runs-on: ubuntu-24.04-arm steps: - - name: Checkout repository + - name: Checkout uses: actions/checkout@v4 - - name: Download labels' config + - name: Labels' config shell: bash run: | mkdir -p .tmp curl -LsS https://raw.githubusercontent.com/devops-infra/.github/master/.github/labels.yml -o .tmp/labels.yml - - name: Update labels - dry run + - name: Update labels (dry run) uses: crazy-max/ghaction-github-labeler@v5.2.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -28,52 +27,62 @@ jobs: dry-run: true lint: - name: Run linters + name: Linters if: "!startsWith(github.ref, 'refs/heads/dependabot')" - runs-on: ubuntu-latest + runs-on: ubuntu-24.04-arm steps: - - name: Checkout repository + - name: Checkout uses: actions/checkout@v4 - - name: Docker Lint - uses: luke142367/Docker-Lint-Action@v1.1.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Haskell Dockerfile Linter (Hadolint) - uses: brpaz/hadolint-action@v1.5.0 + - name: Hadolint + uses: hadolint/hadolint-action@v3.1.0 with: dockerfile: Dockerfile - build: - name: Build image - runs-on: ubuntu-latest + build_and_push: + name: Build & push + if: "!startsWith(github.ref, 'refs/heads/dependabot')" + runs-on: ubuntu-24.04-arm steps: - - name: Checkout repository + - name: Checkout uses: actions/checkout@v4 - - name: Build Docker image + - name: Docker Buildx + uses: docker/setup-buildx-action@v3.9.0 + with: + install: true + + - name: QEMU + uses: docker/setup-qemu-action@v3.4.0 + with: + image: tonistiigi/binfmt:latest + platforms: amd64,arm64 + + - name: Build & push env: + DOCKER_BUILDKIT: 1 + DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TERM: xterm-256color - run: make build + run: make push VERSION_PREFIX=test- pull_request: name: Create Pull Request - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - - name: Checkout repository + - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Download Pull Request template + - name: Template shell: bash run: | mkdir -p .tmp curl -LsS https://raw.githubusercontent.com/devops-infra/.github/master/PULL_REQUEST_TEMPLATE.md -o .tmp/PULL_REQUEST_TEMPLATE.md - - name: Create pull request - bugfix (conditional) - if: startsWith(github.ref, 'refs/heads/bugfix') + - name: PR - bugfix (conditional) + if: startsWith(github.ref, 'refs/heads/bug') uses: devops-infra/action-pull-request@v0.5.5 with: github_token: ${{ secrets.GITHUB_TOKEN }} @@ -82,8 +91,8 @@ jobs: template: .tmp/PULL_REQUEST_TEMPLATE.md get_diff: true - - name: Create pull request - dependency (conditional) - if: startsWith(github.ref, 'refs/heads/dependency') + - name: PR - dependency (conditional) + if: "startsWith(github.ref, 'refs/heads/dep') && !startsWith(github.ref, 'refs/heads/dependabot')" uses: devops-infra/action-pull-request@v0.5.5 with: github_token: ${{ secrets.GITHUB_TOKEN }} @@ -92,8 +101,8 @@ jobs: template: .tmp/PULL_REQUEST_TEMPLATE.md get_diff: true - - name: Create pull request - documentation (conditional) - if: startsWith(github.ref, 'refs/heads/documentation') + - name: PR - documentation (conditional) + if: startsWith(github.ref, 'refs/heads/doc') uses: devops-infra/action-pull-request@v0.5.5 with: github_token: ${{ secrets.GITHUB_TOKEN }} @@ -102,8 +111,8 @@ jobs: template: .tmp/PULL_REQUEST_TEMPLATE.md get_diff: true - - name: Create pull request - feature (conditional) - if: startsWith(github.ref, 'refs/heads/feature') + - name: PR - feature (conditional) + if: startsWith(github.ref, 'refs/heads/feat') uses: devops-infra/action-pull-request@v0.5.5 with: github_token: ${{ secrets.GITHUB_TOKEN }} @@ -112,7 +121,7 @@ jobs: template: .tmp/PULL_REQUEST_TEMPLATE.md get_diff: true - - name: Create pull request - test (conditional) + - name: PR - test (conditional) if: startsWith(github.ref, 'refs/heads/test') uses: devops-infra/action-pull-request@v0.5.5 with: @@ -124,8 +133,8 @@ jobs: draft: true get_diff: true - - name: Create pull request - other (conditional) - if: "!startsWith(github.ref, 'refs/heads/bugfix') && !startsWith(github.ref, 'refs/heads/dependabot') && !startsWith(github.ref, 'refs/heads/dependency') && !startsWith(github.ref, 'refs/heads/documentation') && !startsWith(github.ref, 'refs/heads/feature') && !startsWith(github.ref, 'refs/heads/test')" + - name: PR - test (conditional) + if: "!startsWith(github.ref, 'refs/heads/bug') && !startsWith(github.ref, 'refs/heads/dep') && !startsWith(github.ref, 'refs/heads/doc') && !startsWith(github.ref, 'refs/heads/feat') && !startsWith(github.ref, 'refs/heads/test')" uses: devops-infra/action-pull-request@v0.5.5 with: github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Dockerfile b/Dockerfile index e03f95e..5041b4d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,37 @@ # Use a clean tiny image to store artifacts in -FROM ubuntu:jammy-20240808 +FROM ubuntu:24.04 + +# Disable interactive mode +ENV DEBIAN_FRONTEND noninteractive + +# Multi-architecture from buildx +ARG TARGETPLATFORM + +# Copy all needed files +COPY entrypoint.sh / + +# Install needed packages +SHELL ["/bin/bash", "-euxo", "pipefail", "-c"] +# hadolint ignore=DL3008 +RUN chmod +x /entrypoint.sh ;\ + apt-get update -y ;\ + apt-get install --no-install-recommends -y \ + curl \ + gpg-agent \ + software-properties-common ;\ + echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections ;\ + add-apt-repository ppa:git-core/ppa ;\ + curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg ;\ + chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg ;\ + echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null ;\ + apt-get update -y ;\ + apt-get install --no-install-recommends -y \ + git \ + gh \ + hub \ + jq ;\ + apt-get clean ;\ + rm -rf /var/lib/apt/lists/* # Labels for http://label-schema.org/rc1/#build-time-labels # And for https://github.com/opencontainers/image-spec/blob/master/annotations.md @@ -8,7 +40,7 @@ ARG NAME="GitHub Action for creating Pull Requests" ARG DESCRIPTION="GitHub Action that will create a pull request from the current branch" ARG REPO_URL="https://github.com/devops-infra/action-pull-request" ARG AUTHOR="Krzysztof Szyper / ChristophShyper / biotyk@mail.com" -ARG HOMEPAGE="https://christophshyper.github.io/" +ARG HOMEPAGE="https://shyper.pro" ARG BUILD_DATE=2020-04-01T00:00:00Z ARG VCS_REF=abcdef1 ARG VERSION=v0.0 @@ -42,31 +74,6 @@ LABEL \ maintainer="${AUTHOR}" \ repository="${REPO_URL}" -# Copy all needed files -COPY entrypoint.sh / - -# Install needed packages -SHELL ["/bin/bash", "-euxo", "pipefail", "-c"] -# hadolint ignore=DL3008 -RUN chmod +x /entrypoint.sh ;\ - apt-get update -y ;\ - apt-get install --no-install-recommends -y \ - curl \ - gpg-agent \ - software-properties-common ;\ - add-apt-repository ppa:git-core/ppa ;\ - curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg ;\ - chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg ;\ - echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null ;\ - apt-get update -y ;\ - apt-get install --no-install-recommends -y \ - git \ - gh \ - hub \ - jq ;\ - apt-get clean ;\ - rm -rf /var/lib/apt/lists/* - # Finish up CMD ["hub version"] WORKDIR /github/workspace diff --git a/Makefile b/Makefile index f4d7122..7aef8ab 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,13 @@ -.PHONY: help build push +.PHONY: phony phony: help # Release tag for the action -VERSION := v0.5.5 +VERSION := v0.6.0 # GitHub Actions bogus variables GITHUB_REF ?= refs/heads/null GITHUB_SHA ?= aabbccddeeff +VERSION_PREFIX ?= # Other variables and constants CURRENT_BRANCH := $(shell echo $(GITHUB_REF) | sed 's/refs\/heads\///') @@ -15,8 +16,19 @@ DOCKER_USER_ID := christophshyper DOCKER_ORG_NAME := devopsinfra DOCKER_IMAGE := action-pull-request DOCKER_NAME := $(DOCKER_ORG_NAME)/$(DOCKER_IMAGE) +GITHUB_USER_ID := ChristophShyper +GITHUB_ORG_NAME := devops-infra +GITHUB_NAME := ghcr.io/$(GITHUB_ORG_NAME)/$(DOCKER_IMAGE) BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") +# Recognize whether docker buildx is installed or not +DOCKER_CHECK := $(shell docker buildx version 1>&2 2>/dev/null; echo $$?) +ifeq ($(DOCKER_CHECK),0) +DOCKER_COMMAND := docker buildx build --platform linux/amd64,linux/arm64 +else +DOCKER_COMMAND := docker build +endif + # Some cosmetics SHELL := bash TXT_RED := $(shell tput setaf 1) @@ -29,29 +41,52 @@ define NL endef # Main actions + +.PHONY: help help: ## Display help prompt $(info Available options:) @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(TXT_YELLOW)%-25s $(TXT_RESET) %s\n", $$1, $$2}' -build: ## Build Docker image + +.PHONY: build +build: ## Build Docker images $(info $(NL)$(TXT_GREEN) == STARTING BUILD ==$(TXT_RESET)) $(info $(TXT_GREEN)Release tag:$(TXT_YELLOW) $(VERSION)$(TXT_RESET)) $(info $(TXT_GREEN)Current branch:$(TXT_YELLOW) $(CURRENT_BRANCH)$(TXT_RESET)) $(info $(TXT_GREEN)Commit hash:$(TXT_YELLOW) $(GITHUB_SHORT_SHA)$(TXT_RESET)) $(info $(TXT_GREEN)Build date:$(TXT_YELLOW) $(BUILD_DATE)$(TXT_RESET)) - $(info $(NL)$(TXT_GREEN)Building Docker image:$(TXT_YELLOW) $(DOCKER_NAME):$(VERSION)$(TXT_RESET)) - @docker build \ + $(info $(NL)$(TXT_GREEN)Building image: $(TXT_YELLOW)$(DOCKER_NAME):$(VERSION_PREFIX)$(VERSION) $(TXT_GREEN)and $(TXT_YELLOW)$(GITHUB_NAME):$(VERSION_PREFIX)$(VERSION)$(TXT_RESET)$(NL)) + @$(DOCKER_COMMAND) \ --build-arg BUILD_DATE=$(BUILD_DATE) \ --build-arg VCS_REF=$(GITHUB_SHORT_SHA) \ --build-arg VERSION=$(VERSION) \ --file=Dockerfile \ - --tag=$(DOCKER_NAME):$(VERSION) . + --tag=$(DOCKER_NAME):$(VERSION_PREFIX)$(VERSION) \ + --tag=$(DOCKER_NAME):$(VERSION_PREFIX)latest \ + --tag=$(GITHUB_NAME):$(VERSION_PREFIX)$(VERSION) \ + --tag=$(GITHUB_NAME):$(VERSION_PREFIX)latest . + @echo -e "\n$(TXT_GREEN)Build images: $(TXT_YELLOW)$(DOCKER_NAME):$(VERSION_PREFIX)$(VERSION) $(TXT_GREEN)and $(TXT_YELLOW)$(GITHUB_NAME):$(VERSION_PREFIX)$(VERSION)$(TXT_RESET)" -push: ## Push to DockerHub - $(info $(NL)$(TXT_GREEN) == STARTING DEPLOYMENT == $(TXT_RESET)) - $(info $(NL)$(TXT_GREEN)Logging-in to DockerHub$(TXT_RESET)) + +.PHONY: login +login: ## Log into all registries + @echo -e "\n$(TXT_GREEN)Logging to: $(TXT_YELLOW)Docker Hub$(TXT_RESET)" @echo $(DOCKER_TOKEN) | docker login -u $(DOCKER_USER_ID) --password-stdin - $(info $(NL)$(TXT_GREEN)Pushing Docker image:$(TXT_YELLOW) $(DOCKER_NAME):$(VERSION)$(TXT_RESET)) - @docker tag $(DOCKER_NAME):$(VERSION) $(DOCKER_NAME):latest - @docker push $(DOCKER_NAME):$(VERSION) - @docker push $(DOCKER_NAME):latest + @echo -e "\n$(TXT_GREEN)Logging to: $(TXT_YELLOW)GitHub Packages$(TXT_RESET)" + @echo $(GITHUB_TOKEN) | docker login ghcr.io -u $(GITHUB_USER_ID) --password-stdin + + +.PHONY: push +push: login ## Push Docker images + $(info $(NL)$(TXT_GREEN) == STARTING DEPLOYMENT == $(TXT_RESET)) + $(info $(NL)$(TXT_GREEN)Pushing image: $(TXT_YELLOW)$(DOCKER_NAME):$(VERSION_PREFIX)$(VERSION) $(TXT_GREEN)and $(TXT_YELLOW)$(GITHUB_NAME):$(VERSION_PREFIX)$(VERSION)$(TXT_RESET)$(NL)) + @$(DOCKER_COMMAND) --push \ + --build-arg BUILD_DATE=$(BUILD_DATE) \ + --build-arg VCS_REF=$(GITHUB_SHORT_SHA) \ + --build-arg VERSION=$(VERSION) \ + --file=Dockerfile \ + --tag=$(DOCKER_NAME):$(VERSION_PREFIX)$(VERSION) \ + --tag=$(DOCKER_NAME):$(VERSION_PREFIX)latest \ + --tag=$(GITHUB_NAME):$(VERSION_PREFIX)$(VERSION) \ + --tag=$(GITHUB_NAME):$(VERSION_PREFIX)latest . + @echo -e "\n$(TXT_GREEN)Pushed images: $(TXT_YELLOW)$(DOCKER_NAME):$(VERSION_PREFIX)$(VERSION) $(TXT_GREEN)and $(TXT_YELLOW)$(GITHUB_NAME):$(VERSION_PREFIX)$(VERSION)$(TXT_RESET)" diff --git a/README.md b/README.md index 2c9357f..12316ca 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,15 @@ # GitHub Action for creating Pull Requests -**GitHub Action that will create a pull request from the current branch.** +## GitHub Action that will create a pull request from the current branch. + +### Supporting `amd64` and `aarch64/arm64` images! Useful in combination with my other action [devops-infra/action-commit-push](https://github.com/devops-infra/action-commit-push). -Dockerized as [devopsinfra/action-pull-request](https://hub.docker.com/repository/docker/devopsinfra/action-pull-request). +Available in Docker Hub: [devopsinfra/action-pull-request:latest](https://hub.docker.com/repository/docker/devopsinfra/action-pull-request) +
+And GitHub Packages: [ghcr.io/devops-infra/action-pull-request/action-pull-request:latest](https://github.com/devops-infra/action-pull-request/packages) + Features: * Creates pull request if triggered from a current branch or any specified by `source_branch` to a `target_branch`. @@ -37,7 +42,7 @@ Features: ```yaml - name: Run the Action - uses: devops-infra/action-pull-request@v0.5.5 + uses: devops-infra/action-pull-request@master with: github_token: ${{ secrets.GITHUB_TOKEN }} source_branch: development @@ -119,7 +124,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - name: Create pull request - uses: devops-infra/action-pull-request@v0.5.5 + uses: devops-infra/action-pull-request@master with: github_token: ${{ secrets.GITHUB_TOKEN }} title: Automatic pull request @@ -136,12 +141,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@master with: fetch-depth: 0 - name: Run the Action if: startsWith(github.ref, 'refs/heads/feature') - uses: devops-infra/action-pull-request@v0.5.5 + uses: devops-infra/action-pull-request@master with: github_token: ${{ secrets.GITHUB_TOKEN }} title: ${{ github.event.commits[0].message }} diff --git a/action.yml b/action.yml index 9a9c59f..d2e45dd 100644 --- a/action.yml +++ b/action.yml @@ -69,7 +69,7 @@ outputs: description: Pull request URL. runs: using: docker - image: docker://devopsinfra/action-pull-request:v0.5.5 + image: docker://devopsinfra/action-pull-request:v0.6.0 env: GITHUB_TOKEN: ${{ inputs.github_token }} branding: