Skip to content

Commit

Permalink
WIP: Split and merge
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryNguyen5 committed Sep 27, 2024
1 parent 5880258 commit cf16f3b
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 138 deletions.
11 changes: 0 additions & 11 deletions .github/actions/goreleaser-build-sign-publish/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ jobs:
- name: Build, sign, and publish
uses: ./.github/actions/goreleaser-build-sign-publish
with:
enable-docker-publish: "true"
enable-goreleaser-snapshot: "false"
docker-registry: ${{ secrets.aws-ecr-registry }}
goreleaser-config: .goreleaser.yaml
env:
Expand All @@ -47,8 +45,6 @@ jobs:
- name: Build, sign, and publish image
uses: ./.github/actions/goreleaser-build-sign-publish
with:
enable-docker-publish: "true"
enable-goreleaser-snapshot: "true"
docker-registry: ${{ secrets.aws-ecr-registry }}
goreleaser-config: .goreleaser.yaml
```
Expand All @@ -59,8 +55,6 @@ jobs:
- name: Build, sign, and publish
uses: ./.github/actions/goreleaser-build-sign-publish
with:
enable-docker-publish: "true"
enable-goreleaser-snapshot: "false"
enable-cosign: "true"
docker-registry: ${{ secrets.aws-ecr-registry }}
goreleaser-config: .goreleaser.yaml
Expand All @@ -82,9 +76,6 @@ Following inputs can be used as `step.with` keys
| `enable-docker-publish` | Bool | `true` | Enable publishing of Docker images / manifests |
| `docker-registry` | String | `localhost:5001` | Docker registry |
| `docker-image-tag` | String | `develop` | Docker image tag |
| `enable-goreleaser-snapshot` | Bool | `false` | Enable goreleaser build / release snapshot |
| `enable-goreleaser-split` | Bool | `false` | Enable goreleaser build using split and merge |
| `goreleaser-split-arch` | String | `""` | The arch to build the image with - amd64, arm64 |
| `goreleaser-config` | String | `.goreleaser.yaml` | The goreleaser configuration yaml |
| `enable-cosign` | Bool | `false` | Enable signing of Docker images |
| `cosign-public-key` | String | `""` | The public key to be used with cosign for verification |
Expand All @@ -103,8 +94,6 @@ docker run -d --restart=always -p "127.0.0.1:5001:5000" --name registry registry

```sh
GORELEASER_CONFIG=".goreleaser.yaml" \
ENABLE_GORELEASER_SNAPSHOT=true \
ENABLE_DOCKER_PUBLISH=true \
DOCKER_MANIFEST_EXTRA_ARGS="--insecure" \
./.github/actions/goreleaser-build-sign-publish/action_utils goreleaser_release
```
38 changes: 11 additions & 27 deletions .github/actions/goreleaser-build-sign-publish/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ inputs:
default: v2.4.0
required: false
# publishing inputs
enable-docker-publish:
description: Enable publishing of docker images / manifests
default: "true"
required: false
docker-registry:
description: The docker registry
default: localhost:5001
Expand All @@ -26,21 +22,14 @@ inputs:
default: develop
required: false
# goreleaser inputs
goreleaser-release-type:
description: The goreleaser release type, it can be either "nightly", "merge", "snapshot", "release"
default: "snapshot"
required: false
goreleaser-config:
description: "The goreleaser configuration yaml"
default: ".goreleaser.yaml"
required: false
enable-goreleaser-snapshot:
description: Enable goreleaser build / release snapshot
default: "false"
required: false
enable-goreleaser-split:
description: Enable goreleaser split and merge builds
default: "false"
required: false
goreleaser-split-arch:
description: The architecture to split the goreleaser build
required: false
# signing inputs
enable-cosign:
description: Enable signing of docker images
Expand Down Expand Up @@ -68,30 +57,25 @@ runs:
uses: sigstore/cosign-installer@4959ce089c160fddf62f7b42464195ba1a56d382 # v3.6.0
with:
cosign-release: ${{ inputs.cosign-version }}

- name: Login to docker registry
if: inputs.enable-docker-publish == 'true'
# If it starts with "merge" or "release" then we'll be pushing images to a registry
if: ${{ startsWith(inputs.goreleaser-release-type, "nightly") || startsWith(inputs.goreleaser-release-type, "release") }}
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
with:
registry: ${{ inputs.docker-registry }}
- name: Set goreleaser split env
if: inputs.enable-goreleaser-split == 'true'
shell: bash
run: |
echo "GOOS=linux" | tee -a $GITHUB_ENV
echo "GOARCH=${{ inputs.goreleaser-split-arch }}" | tee -a $GITHUB_ENV

- name: Install syft
uses: anchore/sbom-action/download-syft@61119d458adab75f756bc0b9e4bde25725f86a7a # v0.17.2

- name: Run goreleaser release
shell: bash
env:
ENABLE_GORELEASER_SNAPSHOT: ${{ inputs.enable-goreleaser-snapshot }}
ENABLE_GORELEASER_SPLIT: ${{ inputs.enable-goreleaser-split }}
ENABLE_DOCKER_PUBLISH: ${{ inputs.enable-docker-publish }}
GORELEASER_CONFIG: ${{ inputs.goreleaser-config }}
IMAGE_PREFIX: ${{ inputs.docker-registry }}
IMAGE_TAG: ${{ inputs.docker-image-tag }}
GORELEASER_CONFIG: ${{ inputs.goreleaser-config }}
GORELEASER_KEY: ${{ inputs.goreleaser-key }}
GITHUB_TOKEN: ${{ github.token }}
run: |
# https://github.com/orgs/community/discussions/24950
${GITHUB_ACTION_PATH}/action_utils goreleaser_release
${GITHUB_ACTION_PATH}/release.js
36 changes: 0 additions & 36 deletions .github/actions/goreleaser-build-sign-publish/action_utils

This file was deleted.

91 changes: 91 additions & 0 deletions .github/actions/goreleaser-build-sign-publish/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env node
const { execSync } = require("child_process");

function main() {
const goreleaserConfig = mustGetEnv("GORELEASER_CONFIG");
const releaseType = mustGetEnv("RELEASE_TYPE");
const command = constructGoreleaserCommand(releaseType, goreleaserConfig);

if (process.env.DRY_RUN) {
console.log(`Generated command: ${command}`);
console.log("Dry run enabled. Exiting without executing the command.");
return;
} else {
console.log(`Executing command: ${command}`);
execSync(command, { stdio: "inherit" });
}
}

main();

function constructGoreleaserCommand(releaseType, goreleaserConfig) {
const version = getVersion();
const flags = [];

checkReleaseType(releaseType);

let subCmd = "release";
const splitArgs = ["--split", "--clean"];

switch (releaseType) {
case "release":
flags.push(...splitArgs);
break;
case "nightly":
flags.push("--nightly", ...splitArgs);
break;
case "snapshot":
flags.push("--snapshot", ...splitArgs);
break;
case "merge":
flags.push("--merge");
subCmd = "continue";
break;
}

const flagsStr = flags.join(" ");
const command = `CHAINLINK_VERSION=${version} goreleaserpro ${subCmd} --config ${goreleaserConfig} ${flagsStr}`;

return command;
}

function checkReleaseType(releaseType) {
const VALID_RELEASE_TYPES = ["nightly", "merge", "snapshot", "release"];

if (!VALID_RELEASE_TYPES.includes(releaseType)) {
const validReleaseTypesStr = VALID_RELEASE_TYPES.join(", ");
console.error(
`Error: Invalid release type: ${releaseType}. Must be one of: ${validReleaseTypesStr}`
);
}
}

function mustGetEnv(key) {
const val = process.env[key];
if (!val || val.trim() === "") {
console.error(`Error: Environment variable ${key} is not set or empty.`);
process.exit(1);
}

return val.trim();
}

function getVersion() {
try {
const pkgPath = process.cwd() + "/package.json";
console.log("Looking for chainlink version in package.json at: ", pkgPath);
const packageJson = require(pkgPath);
if (!packageJson.version) {
console.error(
'Error: "version" field is missing or empty in package.json.'
);
process.exit(1);
}
console.log("Resolved version: ", packageJson.version);

return packageJson.version;
} catch (err) {
console.error(`Error reading package.json: ${err.message}`);
process.exit(1);
}
}
Loading

0 comments on commit cf16f3b

Please sign in to comment.