From ccc91a938ed624b92669863eecbbab5ee72eecc9 Mon Sep 17 00:00:00 2001 From: iyi Date: Tue, 16 Jan 2024 11:40:47 +0800 Subject: [PATCH] feat: github action workflow init --- .github/CODEOWNERS | 0 .github/dependabot.yml | 11 + .github/labels.yml | 42 ++++ .github/pipeline-descriptor.yml | 13 + .github/release-drafter.yml | 32 +++ .github/workflows/pb-create-package.yml | 231 ++++++++++++++++++ .github/workflows/pb-minimal-labels.yml | 29 +++ .github/workflows/pb-synchronize-labels.yml | 17 ++ .github/workflows/pb-tests.yml | 226 +++++++++++++++++ .github/workflows/pb-update-draft-release.yml | 24 ++ .github/workflows/pb-update-go.yml | 72 ++++++ .github/workflows/pb-update-pipeline.yml | 87 +++++++ .gitignore | 1 + buildpack.toml | 54 ++++ scripts/build.sh | 30 +++ solana/build.go | 2 +- solana/detect.go | 6 +- solana/solana.go | 14 +- 18 files changed, 880 insertions(+), 11 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/dependabot.yml create mode 100644 .github/labels.yml create mode 100644 .github/pipeline-descriptor.yml create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/pb-create-package.yml create mode 100644 .github/workflows/pb-minimal-labels.yml create mode 100644 .github/workflows/pb-synchronize-labels.yml create mode 100644 .github/workflows/pb-tests.yml create mode 100644 .github/workflows/pb-update-draft-release.yml create mode 100644 .github/workflows/pb-update-go.yml create mode 100644 .github/workflows/pb-update-pipeline.yml create mode 100644 buildpack.toml create mode 100755 scripts/build.sh diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..e69de29 diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..2adccd4 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: + - package-ecosystem: gomod + directory: / + schedule: + interval: daily + ignore: + - dependency-name: github.com/onsi/gomega + labels: + - semver:patch + - type:dependency-upgrade diff --git a/.github/labels.yml b/.github/labels.yml new file mode 100644 index 0000000..73f0613 --- /dev/null +++ b/.github/labels.yml @@ -0,0 +1,42 @@ +- name: semver:major + description: A change requiring a major version bump + color: f9d0c4 +- name: semver:minor + description: A change requiring a minor version bump + color: f9d0c4 +- name: semver:patch + description: A change requiring a patch version bump + color: f9d0c4 +- name: type:bug + description: A general bug + color: e3d9fc +- name: type:dependency-upgrade + description: A dependency upgrade + color: e3d9fc +- name: type:documentation + description: A documentation update + color: e3d9fc +- name: type:enhancement + description: A general enhancement + color: e3d9fc +- name: type:question + description: A user question + color: e3d9fc +- name: type:task + description: A general task + color: e3d9fc +- name: type:informational + description: Provides information or notice to the community + color: e3d9fc +- name: type:poll + description: Request for feedback from the community + color: e3d9fc +- name: note:ideal-for-contribution + description: An issue that a contributor can help us with + color: 54f7a8 +- name: note:on-hold + description: We can't start working on this issue yet + color: 54f7a8 +- name: note:good-first-issue + description: A good first issue to get started with + color: 54f7a8 diff --git a/.github/pipeline-descriptor.yml b/.github/pipeline-descriptor.yml new file mode 100644 index 0000000..78d6bb9 --- /dev/null +++ b/.github/pipeline-descriptor.yml @@ -0,0 +1,13 @@ +github: + username: ${{ github.actor }} + token: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }} + +package: + repositories: ["ghcr.io/jjeejj/buildpack-solana"] + register: false + registry_token: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }} + +docker_credentials: + - registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }} diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..b5c1d5b --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,32 @@ +template: $CHANGES +name-template: $RESOLVED_VERSION +tag-template: v$RESOLVED_VERSION +categories: + - title: ⭐️ Enhancements + labels: + - type:enhancement + - title: "\U0001F41E Bug Fixes" + labels: + - type:bug + - title: "\U0001F4D4 Documentation" + labels: + - type:documentation + - title: ⛏ Dependency Upgrades + labels: + - type:dependency-upgrade + - title: "\U0001F6A7 Tasks" + labels: + - type:task +exclude-labels: + - type:question +version-resolver: + major: + labels: + - semver:major + minor: + labels: + - semver:minor + patch: + labels: + - semver:patch + default: patch diff --git a/.github/workflows/pb-create-package.yml b/.github/workflows/pb-create-package.yml new file mode 100644 index 0000000..2a63438 --- /dev/null +++ b/.github/workflows/pb-create-package.yml @@ -0,0 +1,231 @@ +name: Create Package +"on": + release: + types: + - published +jobs: + create-package: + name: Create Package + runs-on: + - ubuntu-latest + steps: + - name: Docker login ghcr.io + if: ${{ (github.event_name != 'pull_request' || ! github.event.pull_request.head.repo.fork) && (github.actor != 'dependabot[bot]') }} + uses: docker/login-action@v2 + with: + password: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }} + registry: ghcr.io + username: ${{ github.actor }} + - uses: actions/setup-go@v4 + with: + go-version: "1.20" + - name: Install create-package + run: | + #!/usr/bin/env bash + + set -euo pipefail + + go install -ldflags="-s -w" github.com/paketo-buildpacks/libpak/cmd/create-package@latest + - name: Install crane + run: | + #!/usr/bin/env bash + + set -euo pipefail + + echo "Installing crane ${CRANE_VERSION}" + + mkdir -p "${HOME}"/bin + echo "${HOME}/bin" >> "${GITHUB_PATH}" + + curl \ + --show-error \ + --silent \ + --location \ + "https://github.com/google/go-containerregistry/releases/download/v${CRANE_VERSION}/go-containerregistry_Linux_x86_64.tar.gz" \ + | tar -C "${HOME}/bin" -xz crane + env: + CRANE_VERSION: 0.8.0 + - name: Install pack + run: | + #!/usr/bin/env bash + + set -euo pipefail + + echo "Installing pack ${PACK_VERSION}" + + mkdir -p "${HOME}"/bin + echo "${HOME}/bin" >> "${GITHUB_PATH}" + + curl \ + --location \ + --show-error \ + --silent \ + "https://github.com/buildpacks/pack/releases/download/v${PACK_VERSION}/pack-v${PACK_VERSION}-linux.tgz" \ + | tar -C "${HOME}"/bin -xz pack + env: + PACK_VERSION: 0.29.0 + - name: Enable pack Experimental + if: ${{ false }} + run: | + #!/usr/bin/env bash + + set -euo pipefail + + echo "Enabling pack experimental features" + + mkdir -p "${HOME}"/.pack + echo "experimental = true" >> "${HOME}"/.pack/config.toml + - uses: actions/checkout@v3 + - if: ${{ false }} + uses: actions/cache@v3 + with: + key: ${{ runner.os }}-go-${{ hashFiles('**/buildpack.toml', '**/package.toml') }} + path: |- + ${{ env.HOME }}/.pack + ${{ env.HOME }}/carton-cache + restore-keys: ${{ runner.os }}-go- + - name: Compute Version + id: version + run: | + #!/usr/bin/env bash + + set -euo pipefail + + if [ -z "${GITHUB_REF+set}" ]; then + echo "GITHUB_REF set to [${GITHUB_REF-}], but should never be empty or unset" + exit 255 + fi + + if [[ ${GITHUB_REF} =~ refs/tags/v([0-9]+\.[0-9]+\.[0-9]+) ]]; then + VERSION=${BASH_REMATCH[1]} + + MAJOR_VERSION="$(echo "${VERSION}" | awk -F '.' '{print $1 }')" + MINOR_VERSION="$(echo "${VERSION}" | awk -F '.' '{print $1 "." $2 }')" + + echo "version-major=${MAJOR_VERSION}" >> "$GITHUB_OUTPUT" + echo "version-minor=${MINOR_VERSION}" >> "$GITHUB_OUTPUT" + elif [[ ${GITHUB_REF} =~ refs/heads/(.+) ]]; then + VERSION=${BASH_REMATCH[1]} + else + VERSION=$(git rev-parse --short HEAD) + fi + + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" + echo "Selected ${VERSION} from + * ref: ${GITHUB_REF} + * sha: ${GITHUB_SHA} + " + - name: Create Package + run: | + #!/usr/bin/env bash + + set -euo pipefail + + # With Go 1.20, we need to set this so that we produce statically compiled binaries + # + # Starting with Go 1.20, Go will produce binaries that are dynamically linked against libc + # which can cause compatibility issues. The compiler links against libc on the build system + # but that may be newer than on the stacks we support. + export CGO_ENABLED=0 + + if [[ "${INCLUDE_DEPENDENCIES}" == "true" ]]; then + create-package \ + --source ${SOURCE_PATH:-.} \ + --cache-location "${HOME}"/carton-cache \ + --destination "${HOME}"/buildpack \ + --include-dependencies \ + --version "${VERSION}" + else + create-package \ + --source ${SOURCE_PATH:-.} \ + --destination "${HOME}"/buildpack \ + --version "${VERSION}" + fi + + PACKAGE_FILE=${SOURCE_PATH:-.}/package.toml + [[ -e ${PACKAGE_FILE} ]] && cp ${PACKAGE_FILE} "${HOME}"/package.toml + printf '[buildpack]\nuri = "%s"\n\n[platform]\nos = "%s"\n' "${HOME}"/buildpack "${OS}" >> "${HOME}"/package.toml + env: + INCLUDE_DEPENDENCIES: "false" + OS: linux + SOURCE_PATH: "" + VERSION: ${{ steps.version.outputs.version }} + - name: Package Buildpack + id: package + run: |- + #!/usr/bin/env bash + + set -euo pipefail + + + PACKAGE_LIST=($PACKAGES) + # Extract first repo (Docker Hub) as the main to package & register + PACKAGE=${PACKAGE_LIST[0]} + + if [[ "${PUBLISH:-x}" == "true" ]]; then + pack buildpack package \ + "${PACKAGE}:${VERSION}" \ + --config "${HOME}"/package.toml \ + --publish + + if [[ -n ${VERSION_MINOR:-} && -n ${VERSION_MAJOR:-} ]]; then + crane tag "${PACKAGE}:${VERSION}" "${VERSION_MINOR}" + crane tag "${PACKAGE}:${VERSION}" "${VERSION_MAJOR}" + fi + crane tag "${PACKAGE}:${VERSION}" latest + echo "digest=$(crane digest "${PACKAGE}:${VERSION}")" >> "$GITHUB_OUTPUT" + + # copy to other repositories specified + for P in "${PACKAGE_LIST[@]}" + do + if [ "$P" != "$PACKAGE" ]; then + crane copy "${PACKAGE}:${VERSION}" "${P}:${VERSION}" + if [[ -n ${VERSION_MINOR:-} && -n ${VERSION_MAJOR:-} ]]; then + crane tag "${P}:${VERSION}" "${VERSION_MINOR}" + crane tag "${P}:${VERSION}" "${VERSION_MAJOR}" + fi + crane tag "${P}:${VERSION}" latest + fi + done + + else + pack buildpack package \ + "${PACKAGE}:${VERSION}" \ + --config "${HOME}"/package.toml \ + --format "${FORMAT}" + fi + env: + PACKAGES: ghcr.io/jjeejj/buildpack-solana + PUBLISH: "true" + VERSION: ${{ steps.version.outputs.version }} + VERSION_MAJOR: ${{ steps.version.outputs.version-major }} + VERSION_MINOR: ${{ steps.version.outputs.version-minor }} + - name: Update release with digest + run: | + #!/usr/bin/env bash + + set -euo pipefail + + PAYLOAD=$(cat "${GITHUB_EVENT_PATH}") + + RELEASE_ID=$(jq -n -r --argjson PAYLOAD "${PAYLOAD}" '$PAYLOAD.release.id') + RELEASE_TAG_NAME=$(jq -n -r --argjson PAYLOAD "${PAYLOAD}" '$PAYLOAD.release.tag_name') + RELEASE_NAME=$(jq -n -r --argjson PAYLOAD "${PAYLOAD}" '$PAYLOAD.release.name') + RELEASE_BODY=$(jq -n -r --argjson PAYLOAD "${PAYLOAD}" '$PAYLOAD.release.body') + + gh api \ + --method PATCH \ + "/repos/:owner/:repo/releases/${RELEASE_ID}" \ + --field "tag_name=${RELEASE_TAG_NAME}" \ + --field "name=${RELEASE_NAME}" \ + --field "body=${RELEASE_BODY///\`${DIGEST}\`}" + env: + DIGEST: ${{ steps.package.outputs.digest }} + GITHUB_TOKEN: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }} + - if: ${{ false }} + uses: docker://ghcr.io/buildpacks/actions/registry/request-add-entry:4.0.1 + with: + address: ghcr.io/jjeejj/buildpack-solana@${{ steps.package.outputs.digest }} + id: amp-buildpacks/hardhat + token: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }} + version: ${{ steps.version.outputs.version }} diff --git a/.github/workflows/pb-minimal-labels.yml b/.github/workflows/pb-minimal-labels.yml new file mode 100644 index 0000000..75ea2ac --- /dev/null +++ b/.github/workflows/pb-minimal-labels.yml @@ -0,0 +1,29 @@ +name: Minimal Labels +"on": + pull_request: + types: + - synchronize + - reopened + - labeled + - unlabeled +jobs: + semver: + name: Minimal Semver Labels + runs-on: + - ubuntu-latest + steps: + - uses: mheap/github-action-required-labels@v4 + with: + count: 1 + labels: semver:major, semver:minor, semver:patch + mode: exactly + type: + name: Minimal Type Labels + runs-on: + - ubuntu-latest + steps: + - uses: mheap/github-action-required-labels@v4 + with: + count: 1 + labels: type:bug, type:dependency-upgrade, type:documentation, type:enhancement, type:question, type:task + mode: exactly diff --git a/.github/workflows/pb-synchronize-labels.yml b/.github/workflows/pb-synchronize-labels.yml new file mode 100644 index 0000000..dbedc76 --- /dev/null +++ b/.github/workflows/pb-synchronize-labels.yml @@ -0,0 +1,17 @@ +name: Synchronize Labels +"on": + push: + branches: + - main + paths: + - .github/labels.yml +jobs: + synchronize: + name: Synchronize Labels + runs-on: + - ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: micnncim/action-label-syncer@v1 + env: + GITHUB_TOKEN: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }} diff --git a/.github/workflows/pb-tests.yml b/.github/workflows/pb-tests.yml new file mode 100644 index 0000000..92a9eb0 --- /dev/null +++ b/.github/workflows/pb-tests.yml @@ -0,0 +1,226 @@ +name: Tests +"on": + merge_group: + types: + - checks_requested + branches: + - main + pull_request: {} + push: + branches: + - main +jobs: + create-package: + name: Create Package Test + runs-on: + - ubuntu-latest + steps: + - name: Docker login ghcr.io + if: ${{ (github.event_name != 'pull_request' || ! github.event.pull_request.head.repo.fork) && (github.actor != 'dependabot[bot]') }} + uses: docker/login-action@v2 + with: + password: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }} + registry: ghcr.io + username: ${{ github.actor }} + - uses: actions/setup-go@v4 + with: + go-version: "1.20" + - name: Install create-package + run: | + #!/usr/bin/env bash + + set -euo pipefail + + go install -ldflags="-s -w" github.com/paketo-buildpacks/libpak/cmd/create-package@latest + - name: Install pack + run: | + #!/usr/bin/env bash + + set -euo pipefail + + echo "Installing pack ${PACK_VERSION}" + + mkdir -p "${HOME}"/bin + echo "${HOME}/bin" >> "${GITHUB_PATH}" + + curl \ + --location \ + --show-error \ + --silent \ + "https://github.com/buildpacks/pack/releases/download/v${PACK_VERSION}/pack-v${PACK_VERSION}-linux.tgz" \ + | tar -C "${HOME}"/bin -xz pack + env: + PACK_VERSION: 0.29.0 + - name: Enable pack Experimental + if: ${{ false }} + run: | + #!/usr/bin/env bash + + set -euo pipefail + + echo "Enabling pack experimental features" + + mkdir -p "${HOME}"/.pack + echo "experimental = true" >> "${HOME}"/.pack/config.toml + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + with: + key: ${{ runner.os }}-go-${{ hashFiles('**/buildpack.toml', '**/package.toml') }} + path: |- + ${{ env.HOME }}/.pack + ${{ env.HOME }}/carton-cache + restore-keys: ${{ runner.os }}-go- + - name: Compute Version + id: version + run: | + #!/usr/bin/env bash + + set -euo pipefail + + if [ -z "${GITHUB_REF+set}" ]; then + echo "GITHUB_REF set to [${GITHUB_REF-}], but should never be empty or unset" + exit 255 + fi + + if [[ ${GITHUB_REF} =~ refs/tags/v([0-9]+\.[0-9]+\.[0-9]+) ]]; then + VERSION=${BASH_REMATCH[1]} + + MAJOR_VERSION="$(echo "${VERSION}" | awk -F '.' '{print $1 }')" + MINOR_VERSION="$(echo "${VERSION}" | awk -F '.' '{print $1 "." $2 }')" + + echo "version-major=${MAJOR_VERSION}" >> "$GITHUB_OUTPUT" + echo "version-minor=${MINOR_VERSION}" >> "$GITHUB_OUTPUT" + elif [[ ${GITHUB_REF} =~ refs/heads/(.+) ]]; then + VERSION=${BASH_REMATCH[1]} + else + VERSION=$(git rev-parse --short HEAD) + fi + + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" + echo "Selected ${VERSION} from + * ref: ${GITHUB_REF} + * sha: ${GITHUB_SHA} + " + - name: Create Package + run: | + #!/usr/bin/env bash + + set -euo pipefail + + # With Go 1.20, we need to set this so that we produce statically compiled binaries + # + # Starting with Go 1.20, Go will produce binaries that are dynamically linked against libc + # which can cause compatibility issues. The compiler links against libc on the build system + # but that may be newer than on the stacks we support. + export CGO_ENABLED=0 + + if [[ "${INCLUDE_DEPENDENCIES}" == "true" ]]; then + create-package \ + --source ${SOURCE_PATH:-.} \ + --cache-location "${HOME}"/carton-cache \ + --destination "${HOME}"/buildpack \ + --include-dependencies \ + --version "${VERSION}" + else + create-package \ + --source ${SOURCE_PATH:-.} \ + --destination "${HOME}"/buildpack \ + --version "${VERSION}" + fi + + PACKAGE_FILE=${SOURCE_PATH:-.}/package.toml + [[ -e ${PACKAGE_FILE} ]] && cp ${PACKAGE_FILE} "${HOME}"/package.toml + printf '[buildpack]\nuri = "%s"\n\n[platform]\nos = "%s"\n' "${HOME}"/buildpack "${OS}" >> "${HOME}"/package.toml + env: + INCLUDE_DEPENDENCIES: "true" + OS: linux + VERSION: ${{ steps.version.outputs.version }} + - name: Package Buildpack + run: |- + #!/usr/bin/env bash + + set -euo pipefail + + + PACKAGE_LIST=($PACKAGES) + # Extract first repo (Docker Hub) as the main to package & register + PACKAGE=${PACKAGE_LIST[0]} + + if [[ "${PUBLISH:-x}" == "true" ]]; then + pack buildpack package \ + "${PACKAGE}:${VERSION}" \ + --config "${HOME}"/package.toml \ + --publish + + if [[ -n ${VERSION_MINOR:-} && -n ${VERSION_MAJOR:-} ]]; then + crane tag "${PACKAGE}:${VERSION}" "${VERSION_MINOR}" + crane tag "${PACKAGE}:${VERSION}" "${VERSION_MAJOR}" + fi + crane tag "${PACKAGE}:${VERSION}" latest + echo "digest=$(crane digest "${PACKAGE}:${VERSION}")" >> "$GITHUB_OUTPUT" + + # copy to other repositories specified + for P in "${PACKAGE_LIST[@]}" + do + if [ "$P" != "$PACKAGE" ]; then + crane copy "${PACKAGE}:${VERSION}" "${P}:${VERSION}" + if [[ -n ${VERSION_MINOR:-} && -n ${VERSION_MAJOR:-} ]]; then + crane tag "${P}:${VERSION}" "${VERSION_MINOR}" + crane tag "${P}:${VERSION}" "${VERSION_MAJOR}" + fi + crane tag "${P}:${VERSION}" latest + fi + done + + else + pack buildpack package \ + "${PACKAGE}:${VERSION}" \ + --config "${HOME}"/package.toml \ + --format "${FORMAT}" + fi + env: + FORMAT: image + PACKAGES: test + VERSION: ${{ steps.version.outputs.version }} + unit: + name: Unit Test + runs-on: + - ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + with: + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + path: ${{ env.HOME }}/go/pkg/mod + restore-keys: ${{ runner.os }}-go- + - uses: actions/setup-go@v4 + with: + go-version: "1.20" + - name: Install richgo + run: | + #!/usr/bin/env bash + + set -euo pipefail + + echo "Installing richgo ${RICHGO_VERSION}" + + mkdir -p "${HOME}"/bin + echo "${HOME}/bin" >> "${GITHUB_PATH}" + + curl \ + --location \ + --show-error \ + --silent \ + "https://github.com/kyoh86/richgo/releases/download/v${RICHGO_VERSION}/richgo_${RICHGO_VERSION}_linux_amd64.tar.gz" \ + | tar -C "${HOME}"/bin -xz richgo + env: + RICHGO_VERSION: 0.3.10 + - name: Run Tests + run: | + #!/usr/bin/env bash + + set -euo pipefail + + richgo test ./... + env: + RICHGO_FORCE_COLOR: "1" diff --git a/.github/workflows/pb-update-draft-release.yml b/.github/workflows/pb-update-draft-release.yml new file mode 100644 index 0000000..3c1ef46 --- /dev/null +++ b/.github/workflows/pb-update-draft-release.yml @@ -0,0 +1,24 @@ +name: Update Draft Release +"on": + push: + branches: + - main +jobs: + update: + name: Update Draft Release + runs-on: + - ubuntu-latest + steps: + - id: release-drafter + uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }} + - uses: actions/checkout@v3 + - name: Update draft release with buildpack information + uses: docker://ghcr.io/paketo-buildpacks/actions/draft-release:main + with: + github_token: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }} + release_body: ${{ steps.release-drafter.outputs.body }} + release_id: ${{ steps.release-drafter.outputs.id }} + release_name: ${{ steps.release-drafter.outputs.name }} + release_tag_name: ${{ steps.release-drafter.outputs.tag_name }} diff --git a/.github/workflows/pb-update-go.yml b/.github/workflows/pb-update-go.yml new file mode 100644 index 0000000..1c6d8f8 --- /dev/null +++ b/.github/workflows/pb-update-go.yml @@ -0,0 +1,72 @@ +name: Update Go +"on": + schedule: + - cron: 20 2 * * 1 + workflow_dispatch: {} +jobs: + update: + name: Update Go + runs-on: + - ubuntu-latest + steps: + - uses: actions/setup-go@v4 + with: + go-version: "1.20" + - uses: actions/checkout@v3 + - name: Update Go Version & Modules + id: update-go + run: | + #!/usr/bin/env bash + + set -euo pipefail + + if [ -z "${GO_VERSION:-}" ]; then + echo "No go version set" + exit 1 + fi + + OLD_GO_VERSION=$(grep -P '^go \d\.\d+' go.mod | cut -d ' ' -f 2) + + go mod edit -go="$GO_VERSION" + go mod tidy + go get -u -t ./... + go mod tidy + + git add go.mod go.sum + git checkout -- . + + if [ "$OLD_GO_VERSION" == "$GO_VERSION" ]; then + COMMIT_TITLE="Bump Go Modules" + COMMIT_BODY="Bumps Go modules used by the project. See the commit for details on what modules were updated." + COMMIT_SEMVER="semver:patch" + else + COMMIT_TITLE="Bump Go from ${OLD_GO_VERSION} to ${GO_VERSION}" + COMMIT_BODY="Bumps Go from ${OLD_GO_VERSION} to ${GO_VERSION} and update Go modules used by the project. See the commit for details on what modules were updated." + COMMIT_SEMVER="semver:minor" + fi + + echo "commit-title=${COMMIT_TITLE}" >> "$GITHUB_OUTPUT" + echo "commit-body=${COMMIT_BODY}" >> "$GITHUB_OUTPUT" + echo "commit-semver=${COMMIT_SEMVER}" >> "$GITHUB_OUTPUT" + env: + GO_VERSION: "1.20" + - uses: peter-evans/create-pull-request@v5 + with: + author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + body: |- + ${{ steps.update-go.outputs.commit-body }} + +
+ Release Notes + ${{ steps.pipeline.outputs.release-notes }} +
+ branch: update/go + commit-message: |- + ${{ steps.update-go.outputs.commit-title }} + + ${{ steps.update-go.outputs.commit-body }} + delete-branch: true + labels: ${{ steps.update-go.outputs.commit-semver }}, type:task + signoff: true + title: ${{ steps.update-go.outputs.commit-title }} + token: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }} diff --git a/.github/workflows/pb-update-pipeline.yml b/.github/workflows/pb-update-pipeline.yml new file mode 100644 index 0000000..fc2fe65 --- /dev/null +++ b/.github/workflows/pb-update-pipeline.yml @@ -0,0 +1,87 @@ +name: Update Pipeline +"on": + push: + branches: + - main + paths: + - .github/pipeline-descriptor.yml + schedule: + - cron: 0 5 * * 1-5 + workflow_dispatch: {} +jobs: + update: + name: Update Pipeline + runs-on: + - ubuntu-latest + steps: + - uses: actions/setup-go@v4 + with: + go-version: "1.20" + - name: Install octo + run: | + #!/usr/bin/env bash + + set -euo pipefail + + go install -ldflags="-s -w" github.com/paketo-buildpacks/pipeline-builder/cmd/octo@latest + - uses: actions/checkout@v3 + - name: Update Pipeline + id: pipeline + run: | + #!/usr/bin/env bash + + set -euo pipefail + + if [[ -f .github/pipeline-version ]]; then + OLD_VERSION=$(cat .github/pipeline-version) + else + OLD_VERSION="0.0.0" + fi + + rm .github/workflows/pb-*.yml || true + octo --descriptor "${DESCRIPTOR}" + + PAYLOAD=$(gh api /repos/paketo-buildpacks/pipeline-builder/releases/latest) + + NEW_VERSION=$(jq -n -r --argjson PAYLOAD "${PAYLOAD}" '$PAYLOAD.name') + echo "${NEW_VERSION}" > .github/pipeline-version + + RELEASE_NOTES=$( + gh api \ + -F text="$(jq -n -r --argjson PAYLOAD "${PAYLOAD}" '$PAYLOAD.body')" \ + -F mode="gfm" \ + -F context="paketo-buildpacks/pipeline-builder" \ + -X POST /markdown + ) + + git add .github/ + git checkout -- . + + echo "old-version=${OLD_VERSION}" >> "$GITHUB_OUTPUT" + echo "new-version=${NEW_VERSION}" >> "$GITHUB_OUTPUT" + + DELIMITER=$(openssl rand -hex 16) # roughly the same entropy as uuid v4 used in https://github.com/actions/toolkit/blob/b36e70495fbee083eb20f600eafa9091d832577d/packages/core/src/file-command.ts#L28 + printf "release-notes<<%s\n%s\n%s\n" "${DELIMITER}" "${RELEASE_NOTES}" "${DELIMITER}" >> "${GITHUB_OUTPUT}" # see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings + env: + DESCRIPTOR: .github/pipeline-descriptor.yml + GITHUB_TOKEN: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }} + - uses: peter-evans/create-pull-request@v5 + with: + author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + body: |- + Bumps pipeline from `${{ steps.pipeline.outputs.old-version }}` to `${{ steps.pipeline.outputs.new-version }}`. + +
+ Release Notes + ${{ steps.pipeline.outputs.release-notes }} +
+ branch: update/pipeline + commit-message: |- + Bump pipeline from ${{ steps.pipeline.outputs.old-version }} to ${{ steps.pipeline.outputs.new-version }} + + Bumps pipeline from ${{ steps.pipeline.outputs.old-version }} to ${{ steps.pipeline.outputs.new-version }}. + delete-branch: true + labels: semver:patch, type:task + signoff: true + title: Bump pipeline from ${{ steps.pipeline.outputs.old-version }} to ${{ steps.pipeline.outputs.new-version }} + token: ${{ secrets.AMP_BUILDPACKS_BOT_GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 8f3f143..7160640 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out +bin # Dependency directories (remove the comment below to include it) # vendor/ diff --git a/buildpack.toml b/buildpack.toml new file mode 100644 index 0000000..9fe1c4f --- /dev/null +++ b/buildpack.toml @@ -0,0 +1,54 @@ +# Copyright (c) The Amphitheatre Authors. All rights reserved. +# +# 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 +# +# https://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. + +api = "0.8" + +[buildpack] + description = "A Cloud Native Buildpack that provides the Hardhat Tool Suite" + homepage = "https://github.com/jjeejj/buildpack-sonala" + id = "amp-buildpacks/hardhat" + keywords = ["sonala", "buildpack"] + sbom-formats = ["application/vnd.cyclonedx+json", "application/vnd.syft+json"] + name = "Paketo Buildpack for sonala" + version = "0.1.0" + + [[buildpack.licenses]] + type = "Apache-2.0" + uri = "https://github.com/amp-buildpacks/hardhat/blob/main/LICENSE" + +[metadata] + include-files = ["LICENSE", "README.md", "bin/build", "bin/detect", "bin/main", "buildpack.toml"] + pre-package = "scripts/build.sh" + + [[metadata.configurations]] + build = true + default = "false" + description = "enable the Hardhat run process" + name = "BP_ENABLE_HARDHAT_PROCESS" + + # from https://github.com/paketo-buildpacks/node-engine/blob/main/buildpack.toml + [[metadata.dependencies]] + deprecation_date = "2026-04-30T00:00:00Z" + id = "node" + name = "Node Engine" + purl = "pkg:generic/node@v20.10.0" + sha256 = "3fe4ec5d70c8b4ffc1461dec83ab23fc70124e137c4cbbe1ccc9d6ae6ec04a7d" + uri = "https://nodejs.org/dist/v20.10.0/node-v20.10.0-linux-x64.tar.xz" + strip-components = 1 + stacks = ["*"] + version = "20.10.0" + licenses = ["0BSD", "Apache-2.0", "Artistic-2.0", "BSD-2-Clause", "BSD-3-Clause", "BSD-4-Clause", "BSD-Source-Code", "CC0-1.0", "ECL-2.0", "ICU", "MIT", "MIT-0", "SHL-0.5", "SHL-0.51", "Unicode-TOU"] + +[[stacks]] + id = "*" diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..38c47f6 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# Copyright (c) The Amphitheatre Authors. All rights reserved. +# +# 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 +# +# https://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. + +set -euo pipefail + + +GOOS="linux" go build -ldflags='-s -w' -o bin/main github.com/jjeejj/Buildpack-solana/cmd + +if [ "${STRIP:-false}" != "false" ]; then + strip bin/main +fi + +if [ "${COMPRESS:-none}" != "none" ]; then + $COMPRESS bin/main +fi + +ln -fs main bin/build +ln -fs main bin/detect diff --git a/solana/build.go b/solana/build.go index c36cd94..eb5028c 100644 --- a/solana/build.go +++ b/solana/build.go @@ -52,7 +52,7 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) { return libcnb.BuildResult{}, fmt.Errorf("unable to find dependency\n%w", err) } - hardhatLayer := NewHardhat(nodeDependency, dc) + hardhatLayer := NewSolana(nodeDependency, dc) hardhatLayer.Logger = b.Logger enableProcess, _ := cr.Resolve("BP_ENABLE_HARDHAT_PROCESS") diff --git a/solana/detect.go b/solana/detect.go index 9d52f87..8d07f25 100644 --- a/solana/detect.go +++ b/solana/detect.go @@ -23,7 +23,7 @@ import ( ) const ( - PlanEntryHardhat = "solana" + PlanEntrySolana = "solana" ) type Detect struct { @@ -44,10 +44,10 @@ func (d Detect) Detect(context libcnb.DetectContext) (libcnb.DetectResult, error Plans: []libcnb.BuildPlan{ { Provides: []libcnb.BuildPlanProvide{ - {Name: PlanEntryHardhat}, + {Name: PlanEntrySolana}, }, Requires: []libcnb.BuildPlanRequire{ - {Name: PlanEntryHardhat}, + {Name: PlanEntrySolana}, }, }, }, diff --git a/solana/solana.go b/solana/solana.go index d4d7d7a..7a1ccdc 100644 --- a/solana/solana.go +++ b/solana/solana.go @@ -29,25 +29,25 @@ import ( "github.com/paketo-buildpacks/libpak/sherpa" ) -type Hardhat struct { +type Solana struct { LayerContributor libpak.DependencyLayerContributor Logger bard.Logger Executor effect.Executor } -func NewHardhat(dependency libpak.BuildpackDependency, cache libpak.DependencyCache) Hardhat { +func NewSolana(dependency libpak.BuildpackDependency, cache libpak.DependencyCache) Solana { contributor := libpak.NewDependencyLayerContributor(dependency, cache, libcnb.LayerTypes{ Build: true, Cache: true, Launch: true, }) - return Hardhat{ + return Solana{ LayerContributor: contributor, Executor: effect.NewExecutor(), } } -func (r Hardhat) Contribute(layer libcnb.Layer) (libcnb.Layer, error) { +func (r Solana) Contribute(layer libcnb.Layer) (libcnb.Layer, error) { r.LayerContributor.Logger = r.Logger return r.LayerContributor.Contribute(layer, func(artifact *os.File) (libcnb.Layer, error) { bin := filepath.Join(layer.Path, "bin") @@ -85,7 +85,7 @@ func (r Hardhat) Contribute(layer libcnb.Layer) (libcnb.Layer, error) { }) } -func (r Hardhat) Execute(command string, args []string) (*bytes.Buffer, error) { +func (r Solana) Execute(command string, args []string) (*bytes.Buffer, error) { buf := &bytes.Buffer{} if err := r.Executor.Execute(effect.Execution{ Command: command, @@ -98,7 +98,7 @@ func (r Hardhat) Execute(command string, args []string) (*bytes.Buffer, error) { return buf, nil } -func (r Hardhat) BuildProcessTypes(enableProcess string) ([]libcnb.Process, error) { +func (r Solana) BuildProcessTypes(enableProcess string) ([]libcnb.Process, error) { processes := []libcnb.Process{} if enableProcess == "true" { @@ -112,6 +112,6 @@ func (r Hardhat) BuildProcessTypes(enableProcess string) ([]libcnb.Process, erro return processes, nil } -func (r Hardhat) Name() string { +func (r Solana) Name() string { return r.LayerContributor.LayerName() }