From 8fedb192e496088595f1f9a67cdda96266d4e79d Mon Sep 17 00:00:00 2001 From: initializ-bot Date: Wed, 19 Jun 2024 13:29:32 +0000 Subject: [PATCH] Updating github-config --- .github/workflows/publish-releases.yml | 41 ++++++++++ .github/workflows/update-go-mod-version.ym | 93 ++++++++++++++++++++++ scripts/build.sh | 2 +- scripts/package.sh | 49 +++++++++--- 4 files changed, 171 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/publish-releases.yml create mode 100644 .github/workflows/update-go-mod-version.ym diff --git a/.github/workflows/publish-releases.yml b/.github/workflows/publish-releases.yml new file mode 100644 index 0000000..4f85719 --- /dev/null +++ b/.github/workflows/publish-releases.yml @@ -0,0 +1,41 @@ +name: Publish Draft Releases + +on: + workflow_dispatch: {} + schedule: + - cron: '0 5 * * WED' # Weekly on Wednesday at 5:00 AM UTC + +concurrency: + group: publish-release + +jobs: + publish: + name: Publish + runs-on: ubuntu-22.04 + steps: + - name: Publish Draft Release With Highest Semantic Version + id: drafts + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + uses: initializ-buildpacks/github-config/actions/release/publish-drafts@main + with: + repo: ${{ github.repository }} + + failure: + name: Alert on Failure + runs-on: ubuntu-22.04 + needs: [ publish ] + if: ${{ always() && needs.publish.result == 'failure' }} + steps: + - name: File Failure Alert Issue + uses: initializ-buildpacks/github-config/actions/issue/file@main + with: + token: ${{ secrets.GITHUB_TOKEN }} + repo: ${{ github.repository }} + label: "failure:release" + comment_if_exists: true + issue_title: "Failure: Publish draft releases" + issue_body: | + Publish All Draft Releases workflow [failed](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}). + comment_body: | + Another failure occurred: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} \ No newline at end of file diff --git a/.github/workflows/update-go-mod-version.ym b/.github/workflows/update-go-mod-version.ym new file mode 100644 index 0000000..35455ac --- /dev/null +++ b/.github/workflows/update-go-mod-version.ym @@ -0,0 +1,93 @@ +name: Update Go version + +on: + schedule: + - cron: '48 4 * * MON' # every monday at 4:48 UTC + workflow_dispatch: + +concurrency: update-go + +jobs: + update-go: + name: Update go toolchain in go.mod + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Checkout PR Branch + uses: initializ-buildpacks/github-config/actions/pull-request/checkout-branch@main + with: + branch: automation/go-mod-update/update-main + - name: Setup Go + id: setup-go + uses: actions/setup-go@v5 + with: + go-version: 'stable' + - name: Get current go toolchain version + id: current-go-version + uses: initializ-buildpacks/github-config/actions/update-go-mod-version@main + with: + toolchain-version: ${{ steps.setup-go.outputs.go-version }} + - name: Go mod tidy + run: | + #!/usr/bin/env bash + set -euo pipefail + shopt -s inherit_errexit + + echo "Before running go mod tidy" + echo "head -n10 go.mod " + head -n10 go.mod + + echo "git diff" + git diff + + echo "Running go mod tidy" + go mod tidy + + echo "After running go mod tidy" + echo "head -n10 go.mod " + head -n10 go.mod + + echo "git diff" + git diff + - name: Commit + id: commit + uses: initializ-buildpacks/github-config/actions/pull-request/create-commit@main + with: + message: "Updates go mod toolchain version to ${{ steps.setup-go.outputs.go-version }}" + pathspec: "." + keyid: ${{ secrets.INITIALIZ_BOT_GPG_SIGNING_KEY_ID }} + key: ${{ secrets.INITIALIZ_BOT_GPG_SIGNING_KEY }} + + - name: Push Branch + if: ${{ steps.commit.outputs.commit_sha != '' }} + uses: initializ-buildpacks/github-config/actions/pull-request/push-branch@main + with: + branch: automation/go-mod-update/update-main + + - name: Open Pull Request + if: ${{ steps.commit.outputs.commit_sha != '' }} + uses: initializ-buildpacks/github-config/actions/pull-request/open@main + with: + token: ${{ secrets.PAT }} + title: "Updates go mod toolchain version to ${{ steps.setup-go.outputs.go-version }}" + branch: automation/go-mod-update/update-main + + failure: + name: Alert on Failure + runs-on: ubuntu-22.04 + needs: [update-go] + if: ${{ always() && needs.update-go.result == 'failure' }} + steps: + - name: File Failure Alert Issue + uses: initializ-buildpacks/github-config/actions/issue/file@main + with: + token: ${{ secrets.GITHUB_TOKEN }} + repo: ${{ github.repository }} + label: "failure:update-go-version" + comment_if_exists: true + issue_title: "Failure: Update Go Mod Version workflow" + issue_body: | + Update Go Mod Version workflow [failed](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}). + comment_body: | + Another failure occurred: https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh index a42012e..f603604 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -58,7 +58,7 @@ function run::build() { names=("detect") - if [ -f "extension.toml" ]; then + if [ -f "${BUILDPACKDIR}/extension.toml" ]; then names+=("generate") else names+=("build") diff --git a/scripts/package.sh b/scripts/package.sh index d58f61c..916363e 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -64,20 +64,25 @@ function main { tools::install "${token}" - buildpack::archive "${version}" - buildpackage::create "${output}" + buildpack_type=buildpack + if [ -f "${ROOT_DIR}/extension.toml" ]; then + buildpack_type=extension + fi + + buildpack::archive "${version}" "${buildpack_type}" + buildpackage::create "${output}" "${buildpack_type}" } function usage() { cat <<-USAGE package.sh --version [OPTIONS] -Packages the buildpack into a buildpackage .cnb file. +Packages a buildpack or an extension into a buildpackage .cnb file. OPTIONS --help -h prints the command usage - --version -v specifies the version number to use when packaging the buildpack - --output -o location to output the packaged buildpackage artifact (default: ${ROOT_DIR}/build/buildpackage.cnb) + --version -v specifies the version number to use when packaging a buildpack or an extension + --output -o location to output the packaged buildpackage or extension artifact (default: ${ROOT_DIR}/build/buildpackage.cnb) --token Token used to download assets from GitHub (e.g. jam, pack, etc) (optional) USAGE } @@ -114,8 +119,9 @@ function tools::install() { function buildpack::archive() { local version version="${1}" + buildpack_type="${2}" - util::print::title "Packaging buildpack into ${BUILD_DIR}/buildpack.tgz..." + util::print::title "Packaging ${buildpack_type} into ${BUILD_DIR}/buildpack.tgz..." if [[ -f "${ROOT_DIR}/.libbuildpack" ]]; then packager \ @@ -125,7 +131,7 @@ function buildpack::archive() { "${BUILD_DIR}/buildpack" else jam pack \ - --buildpack "${ROOT_DIR}/buildpack.toml" \ + "--${buildpack_type}" "${ROOT_DIR}/${buildpack_type}.toml"\ --version "${version}" \ --output "${BUILD_DIR}/buildpack.tgz" fi @@ -134,13 +140,30 @@ function buildpack::archive() { function buildpackage::create() { local output output="${1}" + buildpack_type="${2}" + + util::print::title "Packaging ${buildpack_type}... ${output}" - util::print::title "Packaging buildpack..." + if [ "$buildpack_type" == "extension" ]; then + cwd=$(pwd) + cd ${BUILD_DIR} + mkdir cnbdir + cd cnbdir + cp ../buildpack.tgz . + tar -xvf buildpack.tgz + rm buildpack.tgz - pack \ - buildpack package "${output}" \ - --path "${BUILD_DIR}/buildpack.tgz" \ - --format file + pack \ + extension package "${output}" \ + --format file + + cd $cwd + else + pack \ + buildpack package "${output}" \ + --path "${BUILD_DIR}/buildpack.tgz" \ + --format file + fi } -main "${@:-}" +main "${@:-}" \ No newline at end of file