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 #689

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,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 @@ -3,7 +3,7 @@
on:
workflow_dispatch:
schedule:
- cron: '57 13 * * *' # daily at 13:57 UTC

Check warning on line 6 in .github/workflows/update-dependencies-from-metadata.yml

View workflow job for this annotation

GitHub Actions / lintYaml

6:27 [comments] too few spaces before comment

jobs:
retrieve:
Expand All @@ -12,6 +12,9 @@
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 @@
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 @@

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 @@


- 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 @@
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 @@
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 @@
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 @@
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 @@

# 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@

- 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