This repository has been archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
235 additions
and
196 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ on: | |
jobs: | ||
debug_info: | ||
name: Debug info | ||
runs-on: ubuntu-18.04 | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Print github context JSON | ||
run: | | ||
|
@@ -23,9 +23,10 @@ jobs: | |
EOF | ||
gather_facts: | ||
name: Gather facts | ||
runs-on: ubuntu-18.04 | ||
runs-on: ubuntu-20.04 | ||
outputs: | ||
project_go_path: ${{ steps.get_project_go_path.outputs.path }} | ||
ref_version: ${{ steps.ref_version.outputs.refversion }} | ||
version: ${{ steps.get_version.outputs.version }} | ||
steps: | ||
- name: Get version | ||
|
@@ -34,13 +35,13 @@ jobs: | |
title="$(echo "${{ github.event.head_commit.message }}" | head -n 1 -)" | ||
# Matches strings like: | ||
# | ||
# - "release v1.2.3" | ||
# - "release v1.2.3-r4" | ||
# - "release v1.2.3 (#56)" | ||
# - "release v1.2.3-r4 (#56)" | ||
# - "Release v1.2.3" | ||
# - "Release v1.2.3-r4" | ||
# - "Release v1.2.3 (#56)" | ||
# - "Release v1.2.3-r4 (#56)" | ||
# | ||
# And outputs version part (1.2.3). | ||
if echo $title | grep -qE '^release v[0-9]+\.[0-9]+\.[0-9]+([.-][^ .-][^ ]*)?( \(#[0-9]+\))?$' ; then | ||
if echo $title | grep -iqE '^Release v[0-9]+\.[0-9]+\.[0-9]+([.-][^ .-][^ ]*)?( \(#[0-9]+\))?$' ; then | ||
version=$(echo $title | cut -d ' ' -f 2) | ||
fi | ||
version="${version#v}" # Strip "v" prefix. | ||
|
@@ -59,68 +60,49 @@ jobs: | |
fi | ||
echo "path=\"$path\"" | ||
echo "::set-output name=path::${path}" | ||
install_semver: | ||
name: Install semver | ||
runs-on: ubuntu-18.04 | ||
env: | ||
BINARY: "semver" | ||
URL: "https://raw.githubusercontent.com/fsaintjacques/semver-tool/3.0.0/src/semver" | ||
steps: | ||
- name: Key | ||
id: key | ||
run: | | ||
cache_dir="/opt/cache" | ||
cache_key="install-${BINARY}-${URL}" | ||
echo "::set-output name=binary::${BINARY}" | ||
echo "::set-output name=cache_dir::${cache_dir}" | ||
echo "::set-output name=cache_key::${cache_key}" | ||
echo "::set-output name=url::${URL}" | ||
- name: Cache | ||
id: cache | ||
uses: actions/cache@v1 | ||
with: | ||
key: "${{ steps.key.outputs.cache_key }}" | ||
path: "${{ steps.key.outputs.cache_dir }}" | ||
- name: Download | ||
if: ${{ steps.cache.outputs.cache-hit != 'true' }} | ||
- name: Check if reference version | ||
id: ref_version | ||
run: | | ||
# TODO check hash | ||
binary="${{ steps.key.outputs.binary }}" | ||
cache_dir="${{ steps.key.outputs.cache_dir }}" | ||
url="${{ steps.key.outputs.url }}" | ||
mkdir $cache_dir | ||
curl -fsSLo $cache_dir/$binary $url | ||
chmod +x $cache_dir/$binary | ||
- name: Smoke test | ||
run: | | ||
${{ steps.key.outputs.cache_dir }}/${{ steps.key.outputs.binary }} --version | ||
- name: Upload artifact | ||
uses: actions/upload-artifact@v1 | ||
with: | ||
name: "${{ steps.key.outputs.binary }}" | ||
path: "${{ steps.key.outputs.cache_dir }}/${{ steps.key.outputs.binary }}" | ||
title="$(echo "${{ github.event.head_commit.message }}" | head -n 1 -)" | ||
if echo $title | grep -qE '^release v[0-9]+\.[0-9]+\.[0-9]+([.-][^ .-][^ ]*)?( \(#[0-9]+\))?$' ; then | ||
version=$(echo $title | cut -d ' ' -f 2) | ||
fi | ||
version=$(echo $title | cut -d ' ' -f 2) | ||
version="${version#v}" # Strip "v" prefix. | ||
refversion=false | ||
if [[ "${version}" =~ ^[0-9]+.[0-9]+.[0-9]+-[0-9]+$ ]]; then | ||
refversion=true | ||
fi | ||
echo "refversion =\"$refversion\"" | ||
echo "::set-output name=refversion::$refversion" | ||
update_project_go: | ||
name: Update project.go | ||
runs-on: ubuntu-18.04 | ||
if: ${{ needs.gather_facts.outputs.version != '' && needs.gather_facts.outputs.project_go_path != ''}} | ||
runs-on: ubuntu-20.04 | ||
if: ${{ needs.gather_facts.outputs.version != '' && needs.gather_facts.outputs.project_go_path != '' && needs.gather_facts.outputs.ref_version != 'true' }} | ||
needs: | ||
- gather_facts | ||
- install_semver | ||
steps: | ||
- name: Download semver artifact to /opt/bin | ||
uses: actions/download-artifact@v2 | ||
- name: Install architect | ||
uses: giantswarm/[email protected] | ||
with: | ||
name: semver | ||
path: /opt/bin | ||
- name: Prepare /opt/bin | ||
run: | | ||
chmod +x /opt/bin/* | ||
echo "::add-path::/opt/bin" | ||
binary: "architect" | ||
version: "3.0.5" | ||
- name: Install semver | ||
uses: giantswarm/[email protected] | ||
with: | ||
binary: "semver" | ||
version: "3.0.0" | ||
download_url: "https://github.com/fsaintjacques/${binary}-tool/archive/${version}.tar.gz" | ||
tarball_binary_path: "*/src/${binary}" | ||
smoke_test: "${binary} --version" | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Update project.go | ||
id: update_project_go | ||
env: | ||
branch: "${{ github.ref }}-version-bump" | ||
run: | | ||
git checkout -b ${{ env.branch }} | ||
file="${{ needs.gather_facts.outputs.project_go_path }}" | ||
version="${{ needs.gather_facts.outputs.version }}" | ||
new_version="$(semver bump patch $version)-dev" | ||
|
@@ -137,15 +119,25 @@ jobs: | |
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git add $file | ||
git commit -m "pkg/project: bump version to ${{ steps.update_project_go.outputs.new_version }}" | ||
git commit -m "Bump version to ${{ steps.update_project_go.outputs.new_version }}" | ||
- name: Push changes | ||
env: | ||
REMOTE_REPO: "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" | ||
branch: "${{ github.ref }}-version-bump" | ||
run: | | ||
git push "${REMOTE_REPO}" HEAD:${{ env.branch }} | ||
- name: Create PR | ||
env: | ||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | ||
base: "${{ github.ref }}" | ||
branch: "${{ github.ref }}-version-bump" | ||
version: "${{ needs.gather_facts.outputs.version }}" | ||
title: "Bump version to ${{ steps.update_project_go.outputs.new_version }}" | ||
run: | | ||
git push "${REMOTE_REPO}" HEAD:${{ github.ref }} | ||
hub pull-request -f -m "${{ env.title }}" -b ${{ env.base }} -h ${{ env.branch }} -r ${{ github.actor }} | ||
create_release: | ||
name: Create release | ||
runs-on: ubuntu-18.04 | ||
runs-on: ubuntu-20.04 | ||
needs: | ||
- gather_facts | ||
if: ${{ needs.gather_facts.outputs.version }} | ||
|
@@ -157,7 +149,7 @@ jobs: | |
with: | ||
ref: ${{ github.sha }} | ||
- name: Ensure correct version in project.go | ||
if: ${{ needs.gather_facts.outputs.project_go_path != ''}} | ||
if: ${{ needs.gather_facts.outputs.project_go_path != '' && needs.gather_facts.outputs.ref_version != 'true' }} | ||
run: | | ||
file="${{ needs.gather_facts.outputs.project_go_path }}" | ||
version="${{ needs.gather_facts.outputs.version }}" | ||
|
@@ -180,3 +172,50 @@ jobs: | |
with: | ||
tag_name: "v${{ needs.gather_facts.outputs.version }}" | ||
release_name: "v${{ needs.gather_facts.outputs.version }}" | ||
create-release-branch: | ||
name: Create release branch | ||
runs-on: ubuntu-20.04 | ||
needs: | ||
- gather_facts | ||
if: ${{ needs.gather_facts.outputs.version }} | ||
steps: | ||
- name: Check out the repository | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 # Clone the whole history, not just the most recent commit. | ||
- name: Fetch all tags and branches | ||
run: "git fetch --all" | ||
- name: Create long-lived release branch | ||
run: | | ||
parent_version="$(git describe --tags --abbrev=0 HEAD^)" | ||
parent_version="${parent_version#v}" # Strip "v" prefix. | ||
echo "parent_version=$parent_version" | ||
release_branch="release-v$(echo ${parent_version} | cut -d '.' -f 1,2).x" | ||
echo "release_branch=${release_branch}" | ||
if git rev-parse --verify ${release_branch} 2>&1 >/dev/null ; then | ||
echo "Release branch ${release_branch} already exists. Nothing to do here." | ||
exit 0 | ||
fi | ||
current_rev=$(git rev-parse HEAD) | ||
has_makefile=$([ -f Makefile ] && echo "yes" || echo "no") | ||
git branch ${release_branch} v${parent_version} | ||
git checkout ${release_branch} | ||
git checkout $current_rev -- .github/workflows | ||
if [[ $has_makefile == "yes" ]] ; then | ||
git checkout $current_rev -- Makefile | ||
fi | ||
git add -A | ||
if ! git diff --cached --exit-code > /dev/null ; then | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git commit -m "Update workflows" | ||
fi | ||
git push origin ${release_branch} |
Oops, something went wrong.