Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates github-config #626

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
18 changes: 18 additions & 0 deletions .github/workflows/create-draft-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,19 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: 'stable'

- name: Checkout
uses: actions/checkout@v3
with:
fetch-tags: true

- name: Reset Draft Release
id: reset
uses: paketo-buildpacks/github-config/actions/release/reset-draft@main
with:
repo: ${{ github.repository }}
token: ${{ github.token }}

- name: Calculate Semver Tag
if: github.event.inputs.version == ''
id: semver
Expand All @@ -84,6 +87,7 @@ jobs:
repo: ${{ github.repository }}
token: ${{ github.token }}
ref-name: ${{ github.ref_name }}

- name: Set Release Tag
id: tag
run: |
Expand All @@ -92,14 +96,28 @@ jobs:
tag="${{ steps.semver.outputs.tag }}"
fi
echo "tag=${tag}" >> "$GITHUB_OUTPUT"

- name: Package
run: ./scripts/package.sh --version "${{ steps.tag.outputs.tag }}"

- name: Get buildpack type
id: get_buildpack_type
run: |

if [ -f "extension.toml" ]; then
echo "buildpack_type=extension" >> "$GITHUB_OUTPUT"
else
echo "buildpack_type=buildpack" >> "$GITHUB_OUTPUT"
fi

- name: Create Release Notes
id: create-release-notes
uses: paketo-buildpacks/github-config/actions/release/notes@main
with:
repo: ${{ github.repository }}
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
buildpack_type: ${{ steps.get_buildpack_type.outputs.buildpack_type }}

- name: Create Release
uses: paketo-buildpacks/github-config/actions/release/create@main
with:
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/push-buildpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ on:
release:
types:
- published
env:
REGISTRIES_FILENAME: "registries.json"

jobs:
push:
name: Push
runs-on: ubuntu-22.04
steps:

- name: Checkout
uses: actions/checkout@v4

- name: Parse Event
id: event
run: |
Expand All @@ -30,6 +35,26 @@ jobs:
output: "/github/workspace/buildpackage.cnb"
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}

- name: Parse Configs
id: parse_configs
run: |
registries_filename="${{ env.REGISTRIES_FILENAME }}"

push_to_dockerhub=true
push_to_gcr=true

if [[ -f $registries_filename ]]; then
if jq 'has("dockerhub")' $registries_filename > /dev/null; then
push_to_dockerhub=$(jq '.dockerhub' $registries_filename)
fi
if jq 'has("GCR")' $registries_filename > /dev/null; then
push_to_gcr=$(jq '.GCR' $registries_filename)
fi
fi

echo "push_to_dockerhub=${push_to_dockerhub}" >> "$GITHUB_OUTPUT"
echo "push_to_gcr=${push_to_gcr}" >> "$GITHUB_OUTPUT"

- name: Validate version
run: |
buidpackTomlVersion=$(sudo skopeo inspect "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" | jq -r '.Labels."io.buildpacks.buildpackage.metadata" | fromjson | .version')
Expand All @@ -40,6 +65,7 @@ jobs:
fi

- name: Push to GCR
if: ${{ steps.parse_configs.outputs.push_to_gcr == 'true' }}
env:
GCR_PUSH_BOT_JSON_KEY: ${{ secrets.GCR_PUSH_BOT_JSON_KEY }}
run: |
Expand All @@ -50,6 +76,7 @@ jobs:
sudo skopeo copy "oci-archive:${GITHUB_WORKSPACE}/buildpackage.cnb" "docker://gcr.io/${{ github.repository }}:latest"

- name: Push to DockerHub
if: ${{ steps.parse_configs.outputs.push_to_dockerhub == 'true' }}
id: push
env:
DOCKERHUB_USERNAME: ${{ secrets.PAKETO_BUILDPACKS_DOCKERHUB_USERNAME }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
uses: actions/checkout@v3

- name: Run Unit Tests
env:
GO_TEST_PARAMS: -count=5
run: ./scripts/unit.sh

- name: Get builders from integration.json
Expand Down Expand Up @@ -80,7 +82,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Upload Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: event-payload
path: ${{ github.event_path }}
111 changes: 84 additions & 27 deletions .github/workflows/update-dependencies-from-metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
outputs:
metadata-filepath: ${{ steps.retrieve.outputs.metadata-filepath }}
metadata-json: ${{ steps.retrieve.outputs.metadata-json }}
# from-source-metadata-filepath is the path to a file containing a subset
# of metadata-json entries for NON-compiled dependencies
from-source-metadata-filepath: ${{ steps.retrieve.outputs.from-source-metadata-filepath }}
# compilation-json is a subset of metadata-json entries which are missing
# a `checksum` and `uri`
compilation-json: ${{ steps.retrieve.outputs.compilation-json }}
Expand All @@ -20,17 +23,21 @@ jobs:
compilation-length: ${{ steps.retrieve.outputs.compilation-length }}
steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 'stable'

- name: Run Retrieve
id: retrieve
working-directory: dependency
run: |
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit

OUTPUT="/tmp/metadata.json"

make retrieve \
Expand All @@ -44,6 +51,9 @@ jobs:

compilation=$(echo $content | jq -r 'map(select(.checksum == null and .uri == null))'?)
complength=$(echo $compilation | jq -r '. | length')
echo $content | jq -r 'map(select(.checksum != null and .uri != null))'? > "/tmp/from-source-metadata.json"
echo "from-source-metadata-filepath=/tmp/from-source-metadata.json" >> "$GITHUB_OUTPUT"


delimiter="$(uuidgen)"
echo "metadata-filepath=${OUTPUT}" >> "$GITHUB_OUTPUT"
Expand All @@ -55,11 +65,17 @@ jobs:


- name: Upload `${{ steps.retrieve.outputs.metadata-filepath }}`
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: metadata.json
path: ${{ steps.retrieve.outputs.metadata-filepath }}

- name: Upload `${{ steps.retrieve.outputs.from-source-metadata-filepath }}`
uses: actions/upload-artifact@v4
with:
name: from-source-metadata.json
path: ${{ steps.retrieve.outputs.from-source-metadata-filepath }}

# Check if there is buildpack-provided compilation code and testing code
# Optional compilation code expected at: <buildpack>/dependency/actions/compile/
# Optional testing code expected at: <buildpack>/dependency/test/
Expand All @@ -71,7 +87,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Has Compilation Action?
id: compile-check
Expand Down Expand Up @@ -106,19 +122,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Make Temporary Artifact Directory
id: make-outputdir
run: |
echo "outputdir=$(mktemp -d)" >> "$GITHUB_OUTPUT"
run: echo "outputdir=$(mktemp -d)" >> "$GITHUB_OUTPUT"

# Download the tarball for testing if:
# (1) dependency testing code is present in the buildpack directory
# (2) URI in metadata.json is available
- name: Download upstream tarball (if not compiled)
if: ${{ matrix.includes.uri != '' && needs.get-compile-and-test.outputs.should-test == 'true' }}
run: |
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit

curl ${{ matrix.includes.uri }} \
--fail-with-body \
--show-error \
Expand All @@ -135,7 +154,6 @@ jobs:
make test \
version="${{ matrix.includes.version }}" \
tarballPath="${{ steps.make-outputdir.outputs.outputdir }}/*.tgz"

compile:
name: Compile and Test Dependency
needs:
Expand All @@ -153,7 +171,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Make Temporary Artifact Directory
id: make-outputdir
Expand All @@ -175,7 +193,7 @@ jobs:

# If compiled, upload the tarball and checksum file for usage in the Update metadata job
- name: Upload workflow asset
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: ${{ needs.get-compile-and-test.outputs.should-compile && matrix.includes.checksum == '' && matrix.includes.uri == '' }}
with:
name: '${{ needs.retrieve.outputs.id }}-${{ matrix.includes.version }}-${{ matrix.includes.target }}'
Expand All @@ -187,6 +205,10 @@ jobs:
working-directory: dependency
if: ${{ needs.get-compile-and-test.outputs.should-test == 'true' }}
run: |
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit

make test \
version="${{ matrix.includes.version }}" \
tarballPath="${{ steps.make-outputdir.outputs.outputdir }}/*.tgz"
Expand All @@ -201,23 +223,24 @@ jobs:
strategy:
matrix:
includes: ${{ fromJSON(needs.retrieve.outputs.compilation-json) }}
# Run metadata update step sequentially so that metadata.json can be
# modified for each version
max-parallel: 1
if: ${{ needs.retrieve.outputs.compilation-length > 0 && needs.get-compile-and-test.outputs.should-compile == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Download artifact files
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: '${{ needs.retrieve.outputs.id }}-${{ matrix.includes.version }}-${{ matrix.includes.target }}'

- name: Get artifact file name
id: get-file-names
run: |
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit

echo "artifact-file=$(basename ./*.tgz)" >> "$GITHUB_OUTPUT"
echo "checksum-file=$(basename ./*.tgz.checksum)" >> "$GITHUB_OUTPUT"

Expand All @@ -241,10 +264,23 @@ jobs:
run: echo "checksum=$(cat ${{ steps.get-file-names.outputs.checksum-file }})" >> "$GITHUB_OUTPUT"

- name: Download metadata.json
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: metadata.json

# Create target/version specific metadata files
# Due to limitations with the upload action, we can no longer modify/upload the same metadata file
- name: Write dependency-specific metadata to new file
id: dependency-metadata
run: |
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit

metadata_file_name="${{ matrix.includes.target }}-${{ matrix.includes.version }}-metadata-file.json"
cat metadata.json | jq -r ['.[] | select( .version == "${{ matrix.includes.version }}" and .target == "${{ matrix.includes.target }}")'] > $metadata_file_name
echo "file=$(echo $metadata_file_name)" >> "$GITHUB_OUTPUT"

- name: Update `checksum` and `uri` in metadata for ${{ matrix.includes.target }} ${{ matrix.includes.version }}
if: ${{ matrix.includes.checksum == '' && matrix.includes.uri == '' }}
uses: paketo-buildpacks/github-config/actions/dependency/update-metadata-json@main
Expand All @@ -253,13 +289,13 @@ jobs:
target: ${{ matrix.includes.target }}
checksum: ${{ steps.get-checksum.outputs.checksum }}
uri: ${{ steps.upload.outputs.dependency-uri }}
file: "metadata.json"
file: ${{ steps.dependency-metadata.outputs.file }}

- name: Upload modified metadata
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: "metadata.json"
path: "metadata.json"
name: ${{ steps.dependency-metadata.outputs.file }}
path: ${{ steps.dependency-metadata.outputs.file }}

assemble:
name: Update buildpack.toml
Expand All @@ -277,7 +313,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Checkout Branch
uses: paketo-buildpacks/github-config/actions/pull-request/checkout-branch@main
Expand All @@ -286,14 +322,35 @@ jobs:

- name: Make Temporary Artifact Directory
id: make-outputdir
run: |
echo "outputdir=$(mktemp -d)" >> "$GITHUB_OUTPUT"
run: echo "outputdir=$(mktemp -d)" >> "$GITHUB_OUTPUT"

- name: Download metadata.json
uses: actions/download-artifact@v3

# Metadata file for the non-compiled dependencies, if there are any
- name: Download metadata.json file
uses: actions/download-artifact@v4
with:
name: metadata.json
path: "${{ steps.make-outputdir.outputs.outputdir }}"
path: "${{ steps.make-outputdir.outputs.outputdir }}/metadata-files"
pattern: "from-source-metadata.json"
merge-multiple: true

# If we compiled the dependency, and updated the metadata:
# Download each metadata file, and combine them into one
- name: Download individual metadata-file.json file(s)
if: ${{ needs.update-metadata.result == 'success' }}
uses: actions/download-artifact@v4
with:
path: "${{ steps.make-outputdir.outputs.outputdir }}/metadata-files"
pattern: "*metadata-file.json"
merge-multiple: true
- name: Display Metadata Files
run: ls "${{ steps.make-outputdir.outputs.outputdir }}/metadata-files"
- name: Combine Metadata Files
run: |
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit

jq -s 'add' ${{ steps.make-outputdir.outputs.outputdir }}/metadata-files/* > "${{ steps.make-outputdir.outputs.outputdir }}/metadata.json"

- name: Update dependencies from metadata.json
id: update
Expand Down
Loading
Loading