Compare commits

...

9 Commits

Author SHA1 Message Date
CrazyMax
f795e92af9 Merge pull request #554 from crazy-max/context-remove-provenanceBuilderID
Some checks failed
publish / publish (push) Has been cancelled
context: remove provenanceBuilderID func
2025-01-15 12:25:00 +01:00
CrazyMax
e46ec802f8 Merge pull request #551 from crazy-max/git-pr-head-ref-optin
context: opt-in pull request head ref
2025-01-15 11:38:38 +01:00
CrazyMax
f2e802cdcd context: remove provenanceBuilderID func
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2025-01-15 10:10:17 +01:00
CrazyMax
e02b7d7dab context: opt-in pull request head ref
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2025-01-15 10:09:18 +01:00
CrazyMax
9881e80bfd Merge pull request #553 from docker/bot/docker-releases-json
Update `.github/docker-releases.json`
2025-01-14 09:48:37 +01:00
crazy-max
a824931115 github: update .github/docker-releases.json
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-01-14 00:27:04 +00:00
CrazyMax
cc12dc0f23 Merge pull request #552 from crazy-max/addlicense-install
dockerfile: use go install for addlicense and update to v1.1.1
2025-01-13 15:03:17 +01:00
CrazyMax
13bd9c8b43 dockerfile: update addlicense to v1.1.1
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2025-01-13 14:29:17 +01:00
CrazyMax
231937b397 dockerfile: use go install for addlicense
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2025-01-13 14:29:02 +01:00
4 changed files with 80 additions and 25 deletions

View File

@@ -1,14 +1,20 @@
{
"latest": {
"id": 190678909,
"tag_name": "v27.4.1",
"html_url": "https://github.com/moby/moby/releases/tag/v27.4.1",
"id": 194138446,
"tag_name": "v27.5.0",
"html_url": "https://github.com/moby/moby/releases/tag/v27.5.0",
"assets": []
},
"v27.5.0": {
"id": 194138446,
"tag_name": "v27.5.0",
"html_url": "https://github.com/moby/moby/releases/tag/v27.5.0",
"assets": []
},
"edge": {
"id": 193567140,
"tag_name": "v27.5.0-rc.2",
"html_url": "https://github.com/moby/moby/releases/tag/v27.5.0-rc.2",
"id": 194138446,
"tag_name": "v27.5.0",
"html_url": "https://github.com/moby/moby/releases/tag/v27.5.0",
"assets": []
},
"v27.5.0-rc.2": {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
import {describe, expect, jest, it, afterEach} from '@jest/globals';
import {describe, expect, jest, it, afterEach, beforeEach, test} from '@jest/globals';
import fs from 'fs';
import os from 'os';
import path from 'path';
@@ -44,6 +44,34 @@ describe('gitRef', () => {
});
});
describe('parseGitRef', () => {
const originalEnv = process.env;
beforeEach(() => {
jest.resetModules();
process.env = {
...originalEnv,
DOCKER_GIT_CONTEXT_PR_HEAD_REF: ''
};
});
afterEach(() => {
process.env = originalEnv;
});
// prettier-ignore
test.each([
['refs/heads/master', '860c1904a1ce19322e91ac35af1ab07466440c37', false, '860c1904a1ce19322e91ac35af1ab07466440c37'],
['master', '860c1904a1ce19322e91ac35af1ab07466440c37', false, '860c1904a1ce19322e91ac35af1ab07466440c37'],
['refs/pull/15/merge', '860c1904a1ce19322e91ac35af1ab07466440c37', false, 'refs/pull/15/merge'],
['refs/heads/master', '', false, 'refs/heads/master'],
['master', '', false, 'master'],
['refs/tags/v1.0.0', '', false, 'refs/tags/v1.0.0'],
['refs/pull/15/merge', '', false, 'refs/pull/15/merge'],
['refs/pull/15/merge', '', true, 'refs/pull/15/head'],
])('given %p and %p, should return %p', async (ref: string, sha: string, prHeadRef: boolean, expected: string) => {
process.env.DOCKER_DEFAULT_GIT_CONTEXT_PR_HEAD_REF = prHeadRef ? 'true' : '';
expect(Context.parseGitRef(ref, sha)).toEqual(expected);
});
});
describe('gitContext', () => {
it('returns refs/heads/master', async () => {
expect(Context.gitContext()).toEqual('https://github.com/docker/actions-toolkit.git#refs/heads/master');

View File

@@ -14,23 +14,44 @@
# See the License for the specific language governing permissions and
# limitations under the License.
ARG ADDLICENSE_VERSION="v1.1.1"
ARG ALPINE_VERSION="3.21"
ARG GO_VERSION="1.23"
ARG XX_VERSION="1.6.1"
ARG LICENSE_HOLDER="actions-toolkit authors"
ARG LICENSE_TYPE="apache"
ARG LICENSE_FILES=".*\(Dockerfile\|Makefile\|\.js\|\.ts\|\.hcl\|\.sh|\.ps1\)"
ARG ADDLICENSE_VERSION="v1.0.0"
FROM ghcr.io/google/addlicense:${ADDLICENSE_VERSION} AS addlicense
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
FROM alpine:3.17 AS base
WORKDIR /src
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
RUN apk add --no-cache cpio findutils git
ENV CGO_ENABLED=0
WORKDIR /src
COPY --link --from=xx / /
FROM base AS addlicense
ARG ADDLICENSE_VERSION
ARG TARGETPLATFORM
RUN --mount=target=/root/.cache,type=cache \
--mount=type=cache,target=/go/pkg/mod <<EOT
set -ex
xx-go install "github.com/google/addlicense@${ADDLICENSE_VERSION}"
mkdir /out
if ! xx-info is-cross; then
mv /go/bin/addlicense /out
else
mv /go/bin/*/addlicense* /out
fi
EOT
FROM base AS set
ARG LICENSE_HOLDER
ARG LICENSE_TYPE
ARG LICENSE_FILES
RUN --mount=type=bind,target=.,rw \
--mount=from=addlicense,source=/app/addlicense,target=/usr/bin/addlicense \
--mount=from=addlicense,source=/out/addlicense,target=/usr/bin/addlicense \
find . -regex "${LICENSE_FILES}" -not -path "./.yarn/*" -not -path "./node_modules/*" | xargs addlicense -c "$LICENSE_HOLDER" -l "$LICENSE_TYPE" && \
mkdir /out && \
find . -regex "${LICENSE_FILES}" -not -path "./.yarn/*" -not -path "./node_modules/*" | cpio -pdm /out
@@ -43,5 +64,5 @@ ARG LICENSE_HOLDER
ARG LICENSE_TYPE
ARG LICENSE_FILES
RUN --mount=type=bind,target=. \
--mount=from=addlicense,source=/app/addlicense,target=/usr/bin/addlicense \
--mount=from=addlicense,source=/out/addlicense,target=/usr/bin/addlicense \
find . -regex "${LICENSE_FILES}" -not -path "./.yarn/*" -not -path "./node_modules/*" | xargs addlicense -check -c "$LICENSE_HOLDER" -l "$LICENSE_TYPE"

View File

@@ -39,23 +39,23 @@ export class Context {
}
public static gitRef(): string {
let gitRef = github.context.ref;
if (github.context.sha && gitRef && !gitRef.startsWith('refs/')) {
gitRef = `refs/heads/${github.context.ref}`;
return Context.parseGitRef(github.context.ref, github.context.sha);
}
public static parseGitRef(ref: string, sha: string): string {
const setPullRequestHeadRef: boolean = !!(process.env.DOCKER_DEFAULT_GIT_CONTEXT_PR_HEAD_REF && process.env.DOCKER_DEFAULT_GIT_CONTEXT_PR_HEAD_REF === 'true');
if (sha && ref && !ref.startsWith('refs/')) {
ref = `refs/heads/${ref}`;
}
if (github.context.sha && !gitRef.startsWith(`refs/pull/`)) {
gitRef = github.context.sha;
} else if (gitRef.startsWith(`refs/pull/`)) {
gitRef = gitRef.replace(/\/merge$/g, '/head');
if (sha && !ref.startsWith(`refs/pull/`)) {
ref = sha;
} else if (ref.startsWith(`refs/pull/`) && setPullRequestHeadRef) {
ref = ref.replace(/\/merge$/g, '/head');
}
return gitRef;
return ref;
}
public static gitContext(): string {
return `${GitHub.serverURL}/${github.context.repo.owner}/${github.context.repo.repo}.git#${Context.gitRef()}`;
}
public static provenanceBuilderID(): string {
return `${GitHub.serverURL}/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}`;
}
}