Skip to content

Commit

Permalink
Merge pull request #1452 from ThatsMrTalbot/feat/makefile-modules
Browse files Browse the repository at this point in the history
feat: add makefile modules for local dev
  • Loading branch information
inteon authored Apr 23, 2024
2 parents 0bf859a + 1974533 commit 47334a6
Show file tree
Hide file tree
Showing 26 changed files with 1,817 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
# Edit https://github.com/cert-manager/makefile-modules/blob/main/modules/repository-base/base/.github/dependabot.yaml instead.

# Update Go dependencies and GitHub Actions dependencies daily.
version: 2
updates:
- package-ecosystem: gomod
directory: /
schedule:
interval: daily
groups:
all:
patterns: ["*"]
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
groups:
all:
patterns: ["*"]
90 changes: 90 additions & 0 deletions .github/workflows/make-self-upgrade.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
# Edit https://github.com/cert-manager/makefile-modules/blob/main/modules/repository-base/base/.github/workflows/make-self-upgrade.yaml instead.

name: make-self-upgrade
concurrency: make-self-upgrade
on:
workflow_dispatch: {}
schedule:
- cron: '0 0 * * *'

jobs:
self_upgrade:
runs-on: ubuntu-latest

permissions:
contents: write
pull-requests: write

env:
SOURCE_BRANCH: "${{ github.ref_name }}"
SELF_UPGRADE_BRANCH: "self-upgrade-${{ github.ref_name }}"

steps:
- name: Fail if branch is not head of branch.
if: ${{ !startsWith(github.ref, 'refs/heads/') && env.SOURCE_BRANCH != '' && env.SELF_UPGRADE_BRANCH != '' }}
run: |
echo "This workflow should not be run on a non-branch-head."
exit 1
- uses: actions/checkout@v4

- id: go-version
run: |
make print-go-version >> "$GITHUB_OUTPUT"
- uses: actions/setup-go@v5
with:
go-version: ${{ steps.go-version.outputs.result }}

- run: |
git checkout -B "$SELF_UPGRADE_BRANCH"
- run: |
make -j upgrade-klone
make -j generate
- id: is-up-to-date
shell: bash
run: |
git_status=$(git status -s)
is_up_to_date="true"
if [ -n "$git_status" ]; then
is_up_to_date="false"
echo "The following changes will be committed:"
echo "$git_status"
fi
echo "result=$is_up_to_date" >> "$GITHUB_OUTPUT"
- if: ${{ steps.is-up-to-date.outputs.result != 'true' }}
run: |
git config --global user.name "cert-manager-bot"
git config --global user.email "[email protected]"
git add -A && git commit -m "BOT: run 'make upgrade-klone' and 'make generate'" --signoff
git push -f origin "$SELF_UPGRADE_BRANCH"
- if: ${{ steps.is-up-to-date.outputs.result != 'true' }}
uses: actions/github-script@v7
with:
script: |
const { repo, owner } = context.repo;
const pulls = await github.rest.pulls.list({
owner: owner,
repo: repo,
head: owner + ':' + process.env.SELF_UPGRADE_BRANCH,
base: process.env.SOURCE_BRANCH,
state: 'open',
});
if (pulls.data.length < 1) {
await github.rest.pulls.create({
title: '[CI] Merge ' + process.env.SELF_UPGRADE_BRANCH + ' into ' + process.env.SOURCE_BRANCH,
owner: owner,
repo: repo,
head: process.env.SELF_UPGRADE_BRANCH,
base: process.env.SOURCE_BRANCH,
body: [
'This PR is auto-generated to bump the Makefile modules.',
].join('\n'),
});
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ public/feed.*

# Our release-process.md tells us to run 'sed' commands that create .bak files.
*.bak

# Makefile modules bin_dir
_bin
109 changes: 109 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Copyright 2023 The cert-manager Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
# Edit https://github.com/cert-manager/makefile-modules/blob/main/modules/repository-base/base/Makefile instead.

# NOTE FOR DEVELOPERS: "How do the Makefiles work and how can I extend them?"
#
# Shared Makefile logic lives in the make/_shared/ directory. The source of truth for these files
# lies outside of this repository, eg. in the cert-manager/makefile-modules repository.
#
# Logic specific to this repository must be defined in the make/00_mod.mk and make/02_mod.mk files:
# - The make/00_mod.mk file is included first and contains variable definitions needed by
# the shared Makefile logic.
# - The make/02_mod.mk file is included later, it can make use of most of the shared targets
# defined in the make/_shared/ directory (all targets defined in 00_mod.mk and 01_mod.mk).
# This file should be used to define targets specific to this repository.

##################################

# Some modules build their dependencies from variables, we want these to be
# evalutated at the last possible moment. For this we use second expansion to
# re-evaluate the generate and verify targets a second time.
#
# See https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html
.SECONDEXPANSION:

# For details on some of these "prelude" settings, see:
# https://clarkgrubb.com/makefile-style-guide
MAKEFLAGS += --warn-undefined-variables --no-builtin-rules
SHELL := /usr/bin/env bash
.SHELLFLAGS := -uo pipefail -c
.DEFAULT_GOAL := help
.DELETE_ON_ERROR:
.SUFFIXES:
FORCE:

noop: # do nothing

##################################
# Host OS and architecture setup #
##################################

# The reason we don't use "go env GOOS" or "go env GOARCH" is that the "go"
# binary may not be available in the PATH yet when the Makefiles are
# evaluated. HOST_OS and HOST_ARCH only support Linux, *BSD and macOS (M1
# and Intel).
HOST_OS ?= $(shell uname -s | tr A-Z a-z)
HOST_ARCH ?= $(shell uname -m)

ifeq (x86_64, $(HOST_ARCH))
HOST_ARCH = amd64
else ifeq (aarch64, $(HOST_ARCH))
# linux reports the arm64 arch as aarch64
HOST_ARCH = arm64
endif

##################################
# Git and versioning information #
##################################

VERSION ?= $(shell git describe --tags --always --match='v*' --abbrev=14 --dirty)
IS_PRERELEASE := $(shell git describe --tags --always --match='v*' --abbrev=0 | grep -q '-' && echo true || echo false)
GITCOMMIT := $(shell git rev-parse HEAD)
GITEPOCH := $(shell git show -s --format=%ct HEAD)

##################################
# Global variables and dirs #
##################################

bin_dir := _bin

# The ARTIFACTS environment variable is set by the CI system to a directory
# where artifacts should be placed. These artifacts are then uploaded to a
# storage bucket by the CI system (https://docs.prow.k8s.io/docs/components/pod-utilities/).
# An example of such an artifact is a jUnit XML file containing test results.
# If the ARTIFACTS environment variable is not set, we default to a local
# directory in the _bin directory.
ARTIFACTS ?= $(bin_dir)/artifacts

$(bin_dir) $(ARTIFACTS) $(bin_dir)/scratch:
mkdir -p $@

.PHONY: clean
## Clean all temporary files
## @category [shared] Tools
clean:
rm -rf $(bin_dir)

##################################
# Include all the Makefiles #
##################################

-include make/00_mod.mk
-include make/_shared/*/00_mod.mk
-include make/_shared/*/01_mod.mk
-include make/02_mod.mk
-include make/_shared/*/02_mod.mk
13 changes: 13 additions & 0 deletions OWNERS_ALIASES
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
# Edit https://github.com/cert-manager/makefile-modules/blob/main/modules/repository-base/base/OWNERS_ALIASES instead.

aliases:
cm-maintainers:
- munnerz
- joshvanl
- wallrj
- jakexks
- maelvls
- irbekrm
- sgtcodfish
- inteon
39 changes: 39 additions & 0 deletions klone.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This klone.yaml file describes the Makefile modules and versions that are
# cloned into the "make/_shared" folder. These modules are dynamically imported
# by the root Makefile. The "make upgrade-klone" target can be used to pull
# the latest version from the upstream repositories (using the repo_ref value).
#
# More info can be found here: https://github.com/cert-manager/makefile-modules

targets:
make/_shared:
- folder_name: boilerplate
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: e9363accaaee20a995bbf8f1c9cba2ea77da8935
repo_path: modules/boilerplate
- folder_name: generate-verify
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: e9363accaaee20a995bbf8f1c9cba2ea77da8935
repo_path: modules/generate-verify
- folder_name: help
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: e9363accaaee20a995bbf8f1c9cba2ea77da8935
repo_path: modules/help
- folder_name: klone
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: e9363accaaee20a995bbf8f1c9cba2ea77da8935
repo_path: modules/klone
- folder_name: repository-base
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: e9363accaaee20a995bbf8f1c9cba2ea77da8935
repo_path: modules/repository-base
- folder_name: tools
repo_url: https://github.com/cert-manager/makefile-modules.git
repo_ref: main
repo_hash: e9363accaaee20a995bbf8f1c9cba2ea77da8935
repo_path: modules/tools
3 changes: 3 additions & 0 deletions make/00_mod.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Node and NPM are installed from the same source, so the versions must match
ADDITIONAL_TOOLS += node=v20.11.1
ADDITIONAL_TOOLS += npm=v20.11.1
53 changes: 53 additions & 0 deletions make/02_mod.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
npm_scripts = build start dev check
.PHONY: $(npm_scripts)
$(npm_scripts): | $(NEEDS_NPM)
$(NPM) run $@

## Vendor the node modules
## @category Development
vendor: | $(NEEDS_NPM)
$(NPM) ci

## Build the site, which then can be served with `make start`
## @category Development
build: vendor

## Serve the site on port 3000
## @category Development
start: vendor

## Start the dev server, this server will reload for every change you make to
## the codebase
## @category Development
dev: vendor

## Run code linting and checks
## @category Development
check: vendor

##########
# NodeJS #
##########

# https://nodejs.org/dist/v20.11.1/SHASUMS256.txt.asc
NODE_linux_amd64_SHA256SUM=bf3a779bef19452da90fb88358ec2c57e0d2f882839b20dc6afc297b6aafc0d7
NODE_linux_arm64_SHA256SUM=e34ab2fc2726b4abd896bcbff0250e9b2da737cbd9d24267518a802ed0606f3b
NODE_darwin_amd64_SHA256SUM=c52e7fb0709dbe63a4cbe08ac8af3479188692937a7bd8e776e0eedfa33bb848
NODE_darwin_arm64_SHA256SUM=e0065c61f340e85106a99c4b54746c5cee09d59b08c5712f67f99e92aa44995d

.PRECIOUS: $(bin_dir)/scratch/node@$(NODE_VERSION)_%
$(bin_dir)/scratch/node@$(NODE_VERSION)_%: | $(bin_dir)/scratch
$(CURL) https://nodejs.org/dist/$(NODE_VERSION)/node-$(NODE_VERSION)-$(subst amd64,x64,$(subst _,-,$*)).tar.gz -o $@.tar.gz
$(checkhash_script) $@.tar.gz $(NODE_$*_SHA256SUM)
mkdir -p $@
tar xzf $@.tar.gz --strip-components=1 -C $@
rm -f $@.tar.gz

$(bin_dir)/downloaded/tools/node@$(NODE_VERSION)_%: | $(bin_dir)/scratch/node@$(NODE_VERSION)_% $(bin_dir)/downloaded/tools
$(LN) $(CURDIR)/$(bin_dir)/scratch/node@$(NODE_VERSION)_$*/bin/node $@

$(bin_dir)/downloaded/tools/npm@$(NPM_VERSION)_%: | $(bin_dir)/scratch/node@$(NPM_VERSION)_% $(bin_dir)/downloaded/tools
$(LN) $(CURDIR)/$(bin_dir)/scratch/node@$(NODE_VERSION)_$*/bin/npm $@

# Export the node bin dir so npm can work
export PATH := $(CURDIR)/$(bin_dir)/scratch/node@$(NODE_VERSION)_$(HOST_OS)_$(HOST_ARCH)/bin:$(PATH)
17 changes: 17 additions & 0 deletions make/_shared/boilerplate/00_mod.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 The cert-manager Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

default_go_header_file := $(dir $(lastword $(MAKEFILE_LIST)))/template/boilerplate.go.txt

go_header_file ?= $(default_go_header_file)
21 changes: 21 additions & 0 deletions make/_shared/boilerplate/01_mod.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2023 The cert-manager Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

.PHONY: verify-boilerplate
## Verify that all files have the correct boilerplate.
## @category [shared] Generate/ Verify
verify-boilerplate: | $(NEEDS_BOILERSUITE)
$(BOILERSUITE) .

shared_verify_targets += verify-boilerplate
Loading

0 comments on commit 47334a6

Please sign in to comment.