-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from buildpacks/buildpack-info
Buildpack Info Action Signed-off-by: Ben Hale <[email protected]>
- Loading branch information
Showing
8 changed files
with
270 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: Create Action buildpack-info | ||
"on": | ||
pull_request: | ||
paths: | ||
- info/** | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- info/** | ||
release: | ||
types: | ||
- published | ||
jobs: | ||
create-action: | ||
name: Create Action | ||
runs-on: | ||
- ubuntu-latest | ||
steps: | ||
- if: ${{ github.event_name != 'pull_request' || ! github.event.pull_request.head.repo.fork }} | ||
name: Docker login ghcr.io | ||
uses: docker/login-action@v1 | ||
with: | ||
password: ${{ secrets.IMPLEMENTATION_GHCR_TOKEN }} | ||
registry: ghcr.io | ||
username: ${{ secrets.IMPLEMENTATION_GHCR_USERNAME }} | ||
- uses: actions/checkout@v2 | ||
- id: version | ||
name: Compute Version | ||
run: | | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
if [[ ${GITHUB_REF} =~ refs/tags/v([0-9]+\.[0-9]+\.[0-9]+) ]]; then | ||
VERSION=${BASH_REMATCH[1]} | ||
elif [[ ${GITHUB_REF} =~ refs/heads/(.+) ]]; then | ||
VERSION=${BASH_REMATCH[1]} | ||
else | ||
VERSION=$(git rev-parse --short HEAD) | ||
fi | ||
echo "::set-output name=version::${VERSION}" | ||
echo "Selected ${VERSION} from | ||
* ref: ${GITHUB_REF} | ||
* sha: ${GITHUB_SHA} | ||
" | ||
- name: Create Action | ||
run: | | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
echo "::group::Building ${TARGET}:${VERSION}" | ||
docker build \ | ||
--file Dockerfile \ | ||
--build-arg "SOURCE=${SOURCE}" \ | ||
--tag "${TARGET}:${VERSION}" \ | ||
. | ||
echo "::endgroup::" | ||
if [[ "${PUSH}" == "true" ]]; then | ||
echo "::group::Pushing ${TARGET}:${VERSION}" | ||
docker push "${TARGET}:${VERSION}" | ||
echo "::endgroup::" | ||
else | ||
echo "Skipping push" | ||
fi | ||
env: | ||
PUSH: ${{ github.event_name != 'pull_request' }} | ||
SOURCE: info/cmd | ||
TARGET: ghcr.io/buildpacks/actions/buildpack-info | ||
VERSION: ${{ steps.version.outputs.version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2018-2020 the original author or authors. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package info | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
|
||
"github.com/buildpacks/libcnb" | ||
"github.com/pelletier/go-toml" | ||
) | ||
|
||
type BuildpackInfo struct { | ||
Path string | ||
Writer io.Writer | ||
} | ||
|
||
func (b BuildpackInfo) Inform() error { | ||
c, err := ioutil.ReadFile(b.Path) | ||
if err != nil { | ||
return fmt.Errorf("unable to read %s\n%w", b.Path, err) | ||
} | ||
|
||
var bp libcnb.Buildpack | ||
if err := toml.Unmarshal(c, &bp); err != nil { | ||
return fmt.Errorf("unable to unmarhal %s\n%w", b.Path, err) | ||
} | ||
|
||
_, _ = fmt.Fprintf(b.Writer, "::set-output name=id::%s\n", bp.Info.ID) | ||
_, _ = fmt.Fprintf(b.Writer, "::set-output name=name::%s\n", bp.Info.Name) | ||
_, _ = fmt.Fprintf(b.Writer, "::set-output name=version::%s\n", bp.Info.Version) | ||
_, _ = fmt.Fprintf(b.Writer, "::set-output name=homepage::%s\n", bp.Info.Homepage) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2020 the original author or authors. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package info_test | ||
|
||
import ( | ||
"bytes" | ||
"path/filepath" | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
"github.com/sclevine/spec" | ||
"github.com/sclevine/spec/report" | ||
|
||
"github.com/buildpacks/github-actions/info" | ||
) | ||
|
||
func TestBuildpackInfo(t *testing.T) { | ||
spec.Run(t, "buildpack-info", func(t *testing.T, when spec.G, it spec.S) { | ||
var ( | ||
Expect = NewWithT(t).Expect | ||
|
||
b = &bytes.Buffer{} | ||
|
||
i = info.BuildpackInfo{ | ||
Path: filepath.Join("testdata", "buildpack.toml"), | ||
Writer: b, | ||
} | ||
) | ||
|
||
it("informs", func() { | ||
Expect(i.Inform()).To(Succeed()) | ||
|
||
Expect(b.String()).To(Equal(`::set-output name=id::test-id | ||
::set-output name=name::test-name | ||
::set-output name=version::test-version | ||
::set-output name=homepage::test-homepage | ||
`, | ||
)) | ||
}) | ||
}, spec.Report(report.Terminal{})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2018-2020 the original author or authors. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/buildpacks/github-actions/info" | ||
) | ||
|
||
func main() { | ||
i := info.BuildpackInfo{ | ||
Path: "buildpack.toml", | ||
Writer: os.Stdout, | ||
} | ||
|
||
if s, ok := os.LookupEnv("INPUT_PATH"); ok { | ||
i.Path = s | ||
} | ||
|
||
if err := i.Inform(); err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2018-2020 the original author or authors. | ||
# | ||
# 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. | ||
|
||
[buildpack] | ||
id = "test-id" | ||
name = "test-name" | ||
version = "test-version" | ||
homepage = "test-homepage" |