draft-release #79
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
name: draft-release | |
on: | |
workflow_dispatch: | |
jobs: | |
draft-release: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Install jq | |
run: | | |
mkdir -p deps/bin | |
curl -s -L -o deps/bin/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 | |
chmod +x deps/bin/jq | |
echo "${PWD}/deps/bin" >> $GITHUB_PATH | |
- name: Derive lifecycle version from branch name | |
run: | | |
[[ $GITHUB_REF =~ ^refs\/heads\/release/(.*)$ ]] && version=${BASH_REMATCH[1]} | |
if [[ -z "${version}" ]]; then | |
echo "lifecycle version not detected." | |
exit 1 | |
fi | |
echo "LIFECYCLE_VERSION=$version" >> $GITHUB_ENV | |
- name: Determine download urls for linux-x86-64, linux-arm64 and windows | |
id: artifact-urls | |
uses: actions/github-script@v3.0.0 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
return github.actions | |
.listRepoWorkflows({ | |
owner: "${{ github.repository_owner }}", | |
repo: "lifecycle", | |
}) | |
.then(workflows_result => { | |
let workflows = workflows_result.data.workflows | |
.filter(a => a.name === "build" && a.state === "active") | |
.map(a => a.id); | |
if (workflows.length === 0) { | |
throw "no active workflows found with name build" | |
} | |
return workflows[0] | |
}) | |
.then(workflow_id => { | |
return github.actions.listWorkflowRunsForRepo({ | |
owner: "${{ github.repository_owner }}", | |
repo: "lifecycle", | |
workflow_id: workflow_id, | |
branch: "release/${{ env.LIFECYCLE_VERSION }}", | |
event: "push" | |
}) | |
}) | |
.then(workflow_runs_result => { | |
let workflow_runs = workflow_runs_result.data.workflow_runs | |
.filter(run => run.conclusion === "success") | |
.filter(run => run.head_sha === "${{ github.sha }}"); | |
if (workflow_runs.length === 0) { | |
throw "no successful workflow runs found for commit" | |
} | |
return workflow_runs[0].id | |
}) | |
.then(workflow_runid => { | |
return github.actions.listWorkflowRunArtifacts({ | |
owner: "${{ github.repository_owner }}", | |
repo: "lifecycle", | |
run_id: workflow_runid | |
}) | |
}) | |
.then(artifacts_result => { | |
let tuples = artifacts_result.data.artifacts | |
.map(artifact => [artifact.name, artifact.archive_download_url]); | |
let urlList = new Array(); | |
tuples.forEach(function(tuple) { | |
if (tuple[0].includes("lifecycle-")) { | |
urlList.push(tuple[1]); | |
} | |
}) | |
if (urlList.length === 0) { | |
throw "no artifacts found" | |
} | |
if (urlList.length != 10) { | |
throw "there should be exactly ten artifacts" | |
} | |
return urlList.join(",") | |
}) | |
- name: Download artifacts | |
run: | | |
mkdir artifacts | |
echo "ARTIFACTS_PATH=$PWD/artifacts" >> $GITHUB_ENV | |
urls=$(echo '${{ steps.artifact-urls.outputs.result }}' | jq -r . ) | |
for url in $(echo $urls | tr "," "\n"); do | |
curl -sL -w 'RESP_CODE:%{response_code}\n' \ | |
--header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ | |
-o tmp-artifact.zip $url | |
unzip -d artifacts tmp-artifact.zip | |
rm tmp-artifact.zip | |
done | |
- name: Combine checksums | |
run: | | |
cd ${{ env.ARTIFACTS_PATH }} | |
cat *.sha256 | sort > lifecycle-v${{ env.LIFECYCLE_VERSION }}-checksums.txt | |
rm *.sha256 | |
- name: Set pre-release kind | |
if: "contains(env.LIFECYCLE_VERSION, 'rc') || contains(env.LIFECYCLE_VERSION, 'pre')" # e.g., 0.99.0-rc.1 | |
run: | | |
echo "RELEASE_KIND=pre-release" >> $GITHUB_ENV | |
- name: Set release kind | |
if: "!contains(env.LIFECYCLE_VERSION, 'rc') && !contains(env.LIFECYCLE_VERSION, 'pre')" | |
run: | | |
echo "RELEASE_KIND=release" >> $GITHUB_ENV | |
- name: Set release body text | |
run: | | |
cat << EOF > body.txt | |
# lifecycle v${{ env.LIFECYCLE_VERSION }} | |
Welcome to v${{ env.LIFECYCLE_VERSION }}, a **beta** ${{ env.RELEASE_KIND }} of the Cloud Native Buildpacks Lifecycle. | |
## Prerequisites | |
The lifecycle runs as a normal user in a series of unprivileged containers. To export images and cache image layers, it requires access to a Docker daemon **or** Docker registry. | |
## Install | |
Extract the .tgz file and copy the lifecycle binaries into a [build stack base image](https://github.com/buildpack/spec/blob/master/platform.md#stacks). The build image can then be orchestrated by a platform implementation such as the [pack CLI](https://github.com/buildpack/pack) or [tekton](https://github.com/tektoncd/catalog/blob/master/task/buildpacks/0.1/README.md). | |
## Lifecycle Image | |
An OCI image containing the lifecycle binaries is available at buildpacksio/lifecycle:${{ env.LIFECYCLE_VERSION }}. | |
EOF | |
- name: Create Pre Release | |
if: "contains(env.LIFECYCLE_VERSION, 'rc') || contains(env.LIFECYCLE_VERSION, 'pre')" # e.g., 0.99.0-rc.1 | |
run: | | |
cd ${{ env.ARTIFACTS_PATH }} | |
gh release create v${{ env.LIFECYCLE_VERSION }} \ | |
$(ls | sort | paste -sd " " -) \ | |
--draft \ | |
--notes-file ../body.txt \ | |
--prerelease \ | |
--target $GITHUB_REF \ | |
--title "lifecycle v${{ env.LIFECYCLE_VERSION }}" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create Release | |
if: "!contains(env.LIFECYCLE_VERSION, 'rc') && !contains(env.LIFECYCLE_VERSION, 'pre')" | |
run: | | |
cd ${{ env.ARTIFACTS_PATH }} | |
gh release create v${{ env.LIFECYCLE_VERSION }} \ | |
$(ls | sort | paste -sd " " -) \ | |
--draft \ | |
--notes-file ../body.txt \ | |
--target $GITHUB_REF \ | |
--title "lifecycle v${{ env.LIFECYCLE_VERSION }}" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |