Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
Initial implementation of the dep-ensure buildpack (#4)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Moran <[email protected]>
Signed-off-by: Arjun Sreedharan <[email protected]>
Signed-off-by: Sophie Wigmore <[email protected]>
Signed-off-by: Forest Eckhardt <[email protected]>
  • Loading branch information
ForestEckhardt authored Jul 9, 2020
1 parent bdcaced commit bc2e13a
Show file tree
Hide file tree
Showing 38 changed files with 1,797 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
86 changes: 86 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Create Release

on:
push:
branches:
- master

jobs:
unit:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.14
- name: Checkout
uses: actions/checkout@v2
- name: Run Unit Tests
run: ./scripts/unit.sh

integration:
name: Integration Tests
runs-on: ubuntu-latest
needs: unit
steps:
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.14
- name: Checkout
uses: actions/checkout@v2
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* || true
- name: Run Integration Tests
run: ./scripts/integration.sh
env:
GIT_TOKEN: ${{ github.token }}

release:
name: Release
runs-on: ubuntu-latest
needs: integration
steps:
- name: Checkout
uses: actions/checkout@v2
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* || true
- name: Tag
id: tag
uses: paketo-buildpacks/github-config/actions/tag@master
- name: Package
run: PACKAGE_DIR=artifact ./scripts/package.sh --version "${{ steps.tag.outputs.tag }}" --archive
- name: Create Release Notes
id: create-release-notes
run: |
mkdir -p "${HOME}/bin"
export PATH="${PATH}:${HOME}/bin"
curl "https://github.com/paketo-buildpacks/packit/releases/download/v0.0.14/jam-linux" \
--silent \
--location \
--output "${HOME}/bin/jam"
chmod +x "${HOME}/bin/jam"
RELEASE_BODY=$(jam summarize --buildpack "${PWD}/artifact.tgz" --format markdown)
# Coz of this messed up issue
# https://github.community/t5/GitHub-Actions/set-output-Truncates-Multiline-Strings/m-p/38372#M3322
RELEASE_BODY="${RELEASE_BODY//'%'/'%25'}"
RELEASE_BODY="${RELEASE_BODY//$'\n'/'%0A'}"
RELEASE_BODY="${RELEASE_BODY//$'\r'/'%0D'}"
echo "::set-output name=release_body::$RELEASE_BODY"
- name: Create Release
uses: paketo-buildpacks/github-config/actions/release/create@master
with:
repo: ${{ github.repository }}
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
tag_name: v${{ steps.tag.outputs.tag }}
target_commitish: ${{ github.sha }}
name: v${{ steps.tag.outputs.tag }}
body: ${{ steps.create-release-notes.outputs.release_body }}
draft: false
assets: |
[
{
"path": "artifact.tgz",
"name": "${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.tgz",
"content_type": "application/gzip"
}
]
20 changes: 20 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Lint

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/[email protected]
with:
version: v1.27
35 changes: 35 additions & 0 deletions .github/workflows/receive-github-config-updates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Sync

on:
repository_dispatch:
types: working-dir-update

jobs:
build:
name: Sync
runs-on: ubuntu-latest
steps:

# checkout paketo github-config as src-repo
- name: Checkout paketo github-config repo
uses: actions/checkout@v2
with:
repository: paketo-buildpacks/github-config
path: config-repo

# checkout this repo
- name: Checkout
uses: actions/checkout@v2
with:
path: current-repo

- name: Run the sync action
uses: paketo-buildpacks/github-config/actions/sync@master
env:
GITHUB_TOKEN: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
with:
config-repo: config-repo
current-repo: current-repo
config-path: "/implementation"
ssh-private-key: ${{ secrets.PAKETO_BOT_SSH_KEY }}
id: do-sync
44 changes: 44 additions & 0 deletions .github/workflows/send-dependency-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This workflow triggers on a published release event.
# Requires the following secrets:
# - LANGUAGE_FAMILY_REPO -> the full name of the repo to send the dispatch to (eg. paketo-buildpacks/nodejs)
# - PAKETO_BOT_GITHUB_TOKEN -> a token with permissions to send the dispatch to the language family repo

name: Send Dependency Update Dispatch

on:
release:
types: [published]

jobs:

dispatch:
runs-on: ubuntu-latest
name: Send Dispatch
steps:

# Parses the release event JSON and fetches the details that make up a dependency update.
# Dependency update details are provided as outputs.
- name: Parse Release Dependency
id: dependency
uses: paketo-buildpacks/github-config/actions/dependency/parse@master

# Generic repository dispatch sender.
- name: Send Repository Dispatch
uses: paketo-buildpacks/github-config/actions/dispatch@master
with:
repos: ${{ secrets.LANGUAGE_FAMILY_REPO }}
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
event: dependency-update
payload: |
{
"strategy": "replace",
"dependency": {
"id": "${{ steps.dependency.outputs.id }}",
"sha256": "${{ steps.dependency.outputs.sha256 }}",
"source": "${{ steps.dependency.outputs.source }}",
"source_sha256": "${{ steps.dependency.outputs.source_sha256 }}",
"stacks": ${{ steps.dependency.outputs.stacks }},
"uri": "${{ steps.dependency.outputs.uri }}",
"version": "${{ steps.dependency.outputs.version }}"
}
}
37 changes: 37 additions & 0 deletions .github/workflows/test-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Test Pull Request

on:
pull_request:
branches:
- master

jobs:
unit:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.14
- name: Checkout
uses: actions/checkout@v2
- name: Run Unit Tests
run: ./scripts/unit.sh

integration:
name: Integration Tests
runs-on: ubuntu-latest
needs: unit
steps:
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.14
- name: Checkout
uses: actions/checkout@v2
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* || true
- name: Run Integration Tests
run: ./scripts/integration.sh
env:
GIT_TOKEN: ${{ github.token }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.bin
12 changes: 12 additions & 0 deletions .mergify/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pull_request_rules:
- name: Auto merge pull requests from github-actions bot
conditions:
- author=github-actions[bot]
# TODO: Fill in these conditions when they are finalized
# - status-success=Unit Tests
# - status-success=Integration Tests
actions:
merge:
strict: true
method: rebase
delete_head_branch: {}
Empty file added .packit
Empty file.
58 changes: 58 additions & 0 deletions build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package depensure

import (
"fmt"
"io/ioutil"
"os"
"time"

"github.com/paketo-buildpacks/packit"
"github.com/paketo-buildpacks/packit/chronos"
)

//go:generate faux --interface BuildProcess --output fakes/build_process.go
type BuildProcess interface {
Execute(workspace, goPath, gocachedir string) (err error)
}

func Build(
buildProcess BuildProcess,
logger LogEmitter,
clock chronos.Clock,
) packit.BuildFunc {

return func(context packit.BuildContext) (packit.BuildResult, error) {
logger.Title("%s %s", context.BuildpackInfo.Name, context.BuildpackInfo.Version)
logger.Process("Executing build process")

depcachedirLayer, err := context.Layers.Get("depcachedir", packit.CacheLayer)
if err != nil {
return packit.BuildResult{}, err
}

gopath, err := ioutil.TempDir("", "gopath")
if err != nil {
return packit.BuildResult{}, fmt.Errorf("failed to create GOPATH directory: %w", err)
}

duration, err := clock.Measure(func() error {
return buildProcess.Execute(context.WorkingDir, gopath, depcachedirLayer.Path)
})

if err != nil {
return packit.BuildResult{}, err
}

err = os.RemoveAll(gopath)
if err != nil {
return packit.BuildResult{}, fmt.Errorf("failed to delete GOPATH directory: %w", err)
}

logger.Action("Completed in %s", duration.Round(time.Millisecond))
logger.Break()

return packit.BuildResult{
Layers: []packit.Layer{depcachedirLayer},
}, nil
}
}
Loading

0 comments on commit bc2e13a

Please sign in to comment.