Skip to content

Commit 39febf1

Browse files
author
Eric Stroczynski
authored
release: push scorecard-test-kuttl images on scorecard-kuttl/v* tags (#4633)
.github/workflows/deploy.yml: only run image deploy jobs for code changes and appropriate tag patterns docs/contribution/guidelines/releasing.md: add scorecard-test-kuttl release section release/Makefile: add scorecard-kuttl tag check to version regexp Signed-off-by: Eric Stroczynski <[email protected]>
1 parent aff0dd6 commit 39febf1

File tree

10 files changed

+173
-55
lines changed

10 files changed

+173
-55
lines changed

.github/workflows/deploy.yml

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- '**'
77
tags:
88
- 'v*'
9+
- 'scorecard-kuttl/v*'
910
pull_request:
1011
branches: [ master ]
1112

@@ -14,22 +15,25 @@ jobs:
1415
name: check_docs_only
1516
runs-on: ubuntu-18.04
1617
outputs:
17-
should_skip_tests: ${{ steps.check_docs_only.outputs.skip-tests }}
18+
is_skip: ${{ steps.check_docs_only.outputs.skip-deploy }}
1819
steps:
1920
- uses: actions/checkout@v2
2021
with:
2122
fetch-depth: 0
2223
- id: check_docs_only
24+
# Since PR's are squashed prior to merging to the branch checked out (default branch),
25+
# HEAD^ will resolve to the previous point in history.
2326
run: |
24-
REPO_MASTER_REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2)
25-
echo "::set-output name=skip-tests::$(hack/ci/check-doc-only-update.sh $REPO_MASTER_REF)"
26-
27+
REF="HEAD^"
28+
[[ -z "${{ github.base_ref }}" ]] || REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2)
29+
echo "::set-output name=skip-deploy::$(hack/ci/check-doc-only-update.sh $REF)"
2730
2831
# Job to test release steps. This will only create a release remotely if run on a tagged commit.
2932
goreleaser:
3033
name: goreleaser
3134
needs: check_docs_only
32-
if: needs.check_docs_only.outputs.should_skip_tests != 'true'
35+
# Run this job on a tag like 'vX.Y.Z' or on a branch or pull request with code changes.
36+
if: startsWith(github.ref, 'refs/tags/v') || ( needs.check_docs_only.outputs.is_skip != 'true' && !startsWith(github.ref, 'refs/tags/') )
3337
runs-on: ubuntu-18.04
3438
environment: deploy
3539
steps:
@@ -51,23 +55,24 @@ jobs:
5155

5256
- name: release
5357
run: |
54-
if [[ $GITHUB_REF != refs/tags/* ]]; then
58+
if [[ $GITHUB_REF != refs/tags/v* ]]; then
5559
export DRY_RUN=1
5660
fi
5761
make release
5862
env:
5963
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6064

61-
# Job matrix for image builds.
65+
# Job matrix for image builds. Only pushes if a tag with prefix "v" is present.
6266
images:
6367
name: images
6468
needs: check_docs_only
65-
if: needs.check_docs_only.outputs.should_skip_tests != 'true'
69+
# Run this job on a tag like 'vX.Y.Z' or on a branch or pull request with code changes.
70+
if: startsWith(github.ref, 'refs/tags/v') || ( needs.check_docs_only.outputs.is_skip != 'true' && !startsWith(github.ref, 'refs/tags/') )
6671
runs-on: ubuntu-18.04
6772
environment: deploy
6873
strategy:
6974
matrix:
70-
id: ["operator-sdk", "ansible-operator", "helm-operator", "scorecard-test", "scorecard-test-kuttl"]
75+
id: ["operator-sdk", "ansible-operator", "helm-operator", "scorecard-test"]
7176
steps:
7277

7378
- name: set up qemu
@@ -84,35 +89,69 @@ jobs:
8489
password: ${{ secrets.QUAY_PASSWORD }}
8590
registry: quay.io
8691

92+
# Check out repo before tag step for script.
93+
- name: checkout
94+
uses: actions/checkout@v2
95+
with:
96+
fetch-depth: 0
97+
8798
- name: create tags
8899
id: tags
89100
run: |
90101
IMG=quay.io/${{ github.repository_owner }}/${{ matrix.id }}
91-
if [[ $GITHUB_REF == refs/tags/* ]]; then
92-
TAG=${GITHUB_REF#refs/tags/}
93-
MAJOR_MINOR=${TAG%.*}
94-
echo ::set-output name=tags::${IMG}:${TAG},${IMG}:${MAJOR_MINOR}
95-
96-
elif [[ $GITHUB_REF == refs/heads/* ]]; then
97-
TAG=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
98-
echo ::set-output name=tags::${IMG}:${TAG}
99-
100-
elif [[ $GITHUB_REF == refs/pull/* ]]; then
101-
TAG=pr-${{ github.event.number }}
102-
echo ::set-output name=tags::${IMG}:${TAG}
103-
fi
102+
echo ::set-output name=tags::$(.github/workflows/get_image_tags.sh "$IMG" "v")
103+
104+
- name: build and push
105+
uses: docker/build-push-action@v2
106+
with:
107+
file: ./images/${{ matrix.id }}/Dockerfile
108+
context: .
109+
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
110+
push: ${{ (github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/') || github.ref == format('refs/heads/{0}', github.event.repository.default_branch) )) }}
111+
tags: ${{ steps.tags.outputs.tags }}
112+
113+
# scorecard-test-kuttl image build job. Only pushes if a tag with prefix "scorecard-kuttl/v" is present.
114+
image-scorecard-test-kuttl:
115+
name: image-scorecard-test-kuttl
116+
needs: check_docs_only
117+
# Run this job on a tag like 'scorecard-kuttl/vX.Y.Z' or on a branch or pull request with code changes.
118+
if: startsWith(github.ref, 'refs/tags/scorecard-kuttl/v') || ( needs.check_docs_only.outputs.is_skip != 'true' && !startsWith(github.ref, 'refs/tags/') )
119+
runs-on: ubuntu-18.04
120+
environment: deploy
121+
steps:
104122

123+
- name: set up qemu
124+
uses: docker/setup-qemu-action@v1
125+
126+
- name: set up buildx
127+
uses: docker/setup-buildx-action@v1
128+
129+
- name: quay.io login
130+
if: github.event_name != 'pull_request'
131+
uses: docker/login-action@v1
132+
with:
133+
username: ${{ secrets.QUAY_USERNAME }}
134+
password: ${{ secrets.QUAY_PASSWORD }}
135+
registry: quay.io
136+
137+
# Check out repo before tag step for script.
105138
- name: checkout
106139
uses: actions/checkout@v2
107140
with:
108141
fetch-depth: 0
109142

143+
- name: create tags
144+
id: tags
145+
run: |
146+
IMG=quay.io/${{ github.repository_owner }}/scorecard-test-kuttl
147+
echo ::set-output name=tags::$(.github/workflows/get_image_tags.sh "$IMG" "scorecard-kuttl/v")
148+
110149
- name: build and push
111150
uses: docker/build-push-action@v2
112151
with:
113-
file: ./images/${{ matrix.id }}/Dockerfile
152+
file: ./images/scorecard-test-kuttl/Dockerfile
114153
context: .
115154
# s390x is not supported by the scorecard-test-kuttl base image.
116-
platforms: linux/amd64,linux/arm64,linux/ppc64le${{ matrix.id != 'scorecard-test-kuttl' && ',linux/s390x' || '' }}
155+
platforms: linux/amd64,linux/arm64,linux/ppc64le
117156
push: ${{ (github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/') || github.ref == format('refs/heads/{0}', github.event.repository.default_branch) )) }}
118157
tags: ${{ steps.tags.outputs.tags }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
IMG="$1"
4+
TAG_PREFIX="$2"
5+
6+
: ${IMG:?"\$1 must be set to an image tag"}
7+
: ${TAG_PREFIX:?"\$2 must be set to some tag prefix to pass to refs/tags/{prefix}*"}
8+
: ${GITHUB_REF:?"GITHUB_REF must be set to a git 'refs/' path in the environment (typically set by the Actions runner)"}
9+
10+
if [[ $GITHUB_REF == refs/tags/${TAG_PREFIX}* ]]; then
11+
# Release tags.
12+
TAG="${GITHUB_REF#refs/tags/${TAG_PREFIX}}"
13+
# Prepend "v" if removed by the above variable operation, since $TAG should always be semver.
14+
[[ $TAG == v* ]] || TAG="v${TAG}"
15+
MAJOR_MINOR="${TAG%.*}"
16+
echo "${IMG}:${TAG},${IMG}:${MAJOR_MINOR}"
17+
18+
elif [[ $GITHUB_REF == refs/tags/* ]]; then
19+
# Any other tag, which will not be pushed.
20+
TAG="$(echo "${GITHUB_REF#refs/tags/}" | sed -r 's|/+|-|g')-local"
21+
echo "${IMG}:${TAG}"
22+
23+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
24+
# Branch build.
25+
TAG="$(echo "${GITHUB_REF#refs/heads/}" | sed -r 's|/+|-|g')"
26+
echo "${IMG}:${TAG}"
27+
28+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
29+
# PR build.
30+
TAG="pr-$(echo "${GITHUB_REF}" | sed -E 's|refs/pull/([^/]+)/?.*|\1|')"
31+
echo "${IMG}:${TAG}"
32+
fi

.github/workflows/integration.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ jobs:
1313
with:
1414
fetch-depth: 0
1515
- id: check_docs_only
16+
# Since PR's are squashed prior to merging to the branch checked out (default branch),
17+
# HEAD^ will resolve to the previous point in history.
1618
run: |
17-
REPO_MASTER_REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2)
18-
echo "::set-output name=skip-tests::$(hack/ci/check-doc-only-update.sh $REPO_MASTER_REF)"
19+
REF="HEAD^"
20+
[[ -z "${{ github.base_ref }}" ]] || REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2)
21+
echo "::set-output name=skip-deploy::$(hack/ci/check-doc-only-update.sh $REF)"
1922
2023
integration:
2124
name: integration

.github/workflows/test-ansible.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ jobs:
1313
with:
1414
fetch-depth: 0
1515
- id: check_docs_only
16+
# Since PR's are squashed prior to merging to the branch checked out (default branch),
17+
# HEAD^ will resolve to the previous point in history.
1618
run: |
17-
REPO_MASTER_REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2)
18-
echo "::set-output name=skip-tests::$(hack/ci/check-doc-only-update.sh $REPO_MASTER_REF)"
19+
REF="HEAD^"
20+
[[ -z "${{ github.base_ref }}" ]] || REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2)
21+
echo "::set-output name=skip-deploy::$(hack/ci/check-doc-only-update.sh $REF)"
1922
2023
e2e:
2124
name: e2e

.github/workflows/test-go.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ jobs:
1313
with:
1414
fetch-depth: 0
1515
- id: check_docs_only
16+
# Since PR's are squashed prior to merging to the branch checked out (default branch),
17+
# HEAD^ will resolve to the previous point in history.
1618
run: |
17-
REPO_MASTER_REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2)
18-
echo "::set-output name=skip-tests::$(hack/ci/check-doc-only-update.sh $REPO_MASTER_REF)"
19+
REF="HEAD^"
20+
[[ -z "${{ github.base_ref }}" ]] || REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2)
21+
echo "::set-output name=skip-deploy::$(hack/ci/check-doc-only-update.sh $REF)"
1922
2023
e2e:
2124
name: e2e

.github/workflows/test-helm.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ jobs:
1313
with:
1414
fetch-depth: 0
1515
- id: check_docs_only
16+
# Since PR's are squashed prior to merging to the branch checked out (default branch),
17+
# HEAD^ will resolve to the previous point in history.
1618
run: |
17-
REPO_MASTER_REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2)
18-
echo "::set-output name=skip-tests::$(hack/ci/check-doc-only-update.sh $REPO_MASTER_REF)"
19+
REF="HEAD^"
20+
[[ -z "${{ github.base_ref }}" ]] || REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2)
21+
echo "::set-output name=skip-deploy::$(hack/ci/check-doc-only-update.sh $REF)"
1922
2023
e2e:
2124
name: e2e

.github/workflows/test-sanity.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ jobs:
1313
with:
1414
fetch-depth: 0
1515
- id: check_docs_only
16+
# Since PR's are squashed prior to merging to the branch checked out (default branch),
17+
# HEAD^ will resolve to the previous point in history.
1618
run: |
17-
REPO_MASTER_REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2)
18-
echo "::set-output name=skip-tests::$(hack/ci/check-doc-only-update.sh $REPO_MASTER_REF)"
19+
REF="HEAD^"
20+
[[ -z "${{ github.base_ref }}" ]] || REF=$(git show-ref ${{ github.base_ref }} | head -1 | cut -d' ' -f2)
21+
echo "::set-output name=skip-deploy::$(hack/ci/check-doc-only-update.sh $REF)"
1922
2023
sanity:
2124
name: sanity

images/scorecard-test-kuttl/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func main() {
6767

6868
jsonOutput, err := json.MarshalIndent(s, "", " ")
6969
if err != nil {
70-
printErrorStatus(fmt.Errorf("could not marshal scoreard output %v", err))
70+
printErrorStatus(fmt.Errorf("could not marshal scorecard output %v", err))
7171
return
7272
}
7373
fmt.Println(string(jsonOutput))

release/Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ SHELL = /bin/bash
77
# Dry run flags.
88
ifneq ($(DRY_RUN),)
99
SNAPSHOT_FLAGS = --snapshot --skip-publish --skip-sign --rm-dist
10-
$(shell touch changelog/generated/$(GIT_VERSION).md)
10+
CHANGELOG = changelog/generated/tmp.md
11+
$(shell touch $(CHANGELOG))
1112
endif
1213

1314
# Ensure that this Makefile is run from the project root (always contains the 'cmd/' directory).
@@ -18,14 +19,15 @@ endif
1819
##@ Release
1920

2021
.PHONY: release
22+
CHANGELOG ?= changelog/generated/$(GIT_VERSION).md
2123
release: ## Publish an operator-sdk release, with option for a dry run with DRY_RUN.
2224
ifeq (,$(GIT_VERSION))
2325
$(error "GIT_VERSION must be set to a git tag")
2426
endif
2527
$(SCRIPTS_DIR)/fetch goreleaser 0.147.2
26-
GORELEASER_CURRENT_TAG=$(GIT_VERSION) $(TOOLS_DIR)/goreleaser $(SNAPSHOT_FLAGS) --release-notes=changelog/generated/$(GIT_VERSION).md --parallelism 5
28+
GORELEASER_CURRENT_TAG=$(GIT_VERSION) $(TOOLS_DIR)/goreleaser $(SNAPSHOT_FLAGS) --release-notes=$(CHANGELOG) --parallelism 5
2729
ifneq ($(DRY_RUN),)
28-
rm changelog/generated/$(GIT_VERSION).md
30+
rm $(CHANGELOG)
2931
endif
3032

3133
##@ Pre-Release
@@ -47,7 +49,7 @@ changelog: check_release_version ## Generate the changelog.
4749
rm -f ./changelog/fragments/!(00-template.yaml)
4850

4951
.PHONY: tag
50-
VERSION_REGEXP := ^v[0-9]+\.[0-9]+\.[0-9]+(\-(alpha|beta|rc)\.[0-9]+)?$
52+
VERSION_REGEXP := ^(scorecard-kuttl/)?v[0-9]+\.[0-9]+\.[0-9]+(\-(alpha|beta|rc)\.[0-9]+)?$
5153
tag: ## Create a release tag.
5254
ifeq (,$(RELEASE_VERSION))
5355
$(error "RELEASE_VERSION must be set to tag HEAD")

0 commit comments

Comments
 (0)