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

Add automation for updating builder lifecycle version #404

Merged
merged 1 commit into from
Oct 19, 2023
Merged
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
71 changes: 71 additions & 0 deletions .github/workflows/update-lifecycle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Update lifecycle

on:
schedule:
# Every Monday at 8am UTC.
- cron: '0 8 * * MON'
workflow_dispatch:

jobs:
update-lifecycle:
name: Update lifecycle
runs-on: pub-hk-ubuntu-22.04-small
steps:
- name: Get token for GH application (Linguist)
uses: heroku/use-app-token-action@main
id: generate-token
with:
app_id: ${{ vars.LINGUIST_GH_APP_ID }}
private_key: ${{ secrets.LINGUIST_GH_PRIVATE_KEY }}

- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ steps.generate-token.outputs.app_token }}

- name: Record existing lifecycle version
id: existing-version
# Having to use grep instead of yq due to:
# https://github.com/mikefarah/yq/issues/1758
run: echo "version=$(grep --perl-regexp --null-data --only-matching '\[lifecycle\]\nversion = "\K([^"]+)' builder-22/builder.toml)" >> "${GITHUB_OUTPUT}"

- name: Determine latest lifecycle version
id: latest-version
run: echo "version=$(gh release view --repo buildpacks/lifecycle --json tagName --jq '.tagName | sub("v"; "")')" >> "${GITHUB_OUTPUT}"

- name: Update builder manifests with latest lifecycle version
# This only updates manifests that were on the same version as builder-22, to ensure
# that any legacy builder images pinned to older lifecycle versions are not updated too.
run: sed --in-place --expression 's/^version = "${{ steps.existing-version.outputs.version }}"$/version = "${{ steps.latest-version.outputs.version }}"/' */builder.toml

# This step will skip creating a PR if there are no changes to commit.
- name: Create pull request
id: pr
uses: peter-evans/[email protected]
with:
token: ${{ steps.generate-token.outputs.app_token }}
title: Update lifecycle from v${{ steps.existing-version.outputs.version }} to v${{ steps.latest-version.outputs.version }}
body: |
Release notes:
https://github.com/buildpacks/lifecycle/releases/tag/v${{ steps.latest-version.outputs.version }}

Full changelog:
https://github.com/buildpacks/lifecycle/compare/v${{ steps.existing-version.outputs.version }}...v${{ steps.latest-version.outputs.version }}
commit-message: |
Update lifecycle from v${{ steps.existing-version.outputs.version }} to v${{ steps.latest-version.outputs.version }}

Release notes:
https://github.com/buildpacks/lifecycle/releases/tag/v${{ steps.latest-version.outputs.version }}

Full changelog:
https://github.com/buildpacks/lifecycle/compare/v${{ steps.existing-version.outputs.version }}...v${{ steps.latest-version.outputs.version }}
branch: update-lifecycle
delete-branch: true
committer: ${{ vars.LINGUIST_GH_APP_USERNAME }} <${{ vars.LINGUIST_GH_APP_EMAIL }}>
author: ${{ vars.LINGUIST_GH_APP_USERNAME }} <${{ vars.LINGUIST_GH_APP_EMAIL }}>

- name: Enable PR auto-merge
if: steps.pr.outputs.pull-request-operation == 'created'
run: gh pr merge --auto --squash "${{ steps.pr.outputs.pull-request-number }}"
env:
GH_TOKEN: ${{ steps.generate-token.outputs.app_token }}