-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from duplocloud/release/0.3.1
Release v0.3.1
- Loading branch information
Showing
6 changed files
with
244 additions
and
153 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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Finish Release | ||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
branches: | ||
- master | ||
env: | ||
git_user: duplo-bot | ||
git_email: [email protected] | ||
jobs: | ||
finish-release: | ||
if: github.event.pull_request.merged == true && (startsWith(github.head_ref, 'refs/heads/release/') || startsWith(github.head_ref, 'release/')) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: master # Always finish releases from the "merged to" master | ||
fetch-depth: 0 | ||
persist-credentials: false # Needed so we can push with different credentials. | ||
# NOTE: Pushing with different credentials allows admins to push protected branches. | ||
# NOTE: Pushing with different credentials allow workflows to trigger from the push. | ||
|
||
# FINISH THE RELEASE | ||
- name: Initialize mandatory git config | ||
run: | | ||
git config --global user.name $git_user && | ||
git config --global user.email $git_email | ||
- name: Finish gitflow release | ||
id: finish-release | ||
uses: duplocloud/ghactions-finish-gitflow-release@master | ||
with: | ||
github_token: ${{ secrets.DUPLO_GITHUB_TOKEN }} | ||
|
||
version-bump: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- finish-release | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: develop | ||
|
||
# BUMP THE DEVELOPMENT VERSION | ||
- name: Initialize mandatory git config | ||
run: | | ||
git config --global user.name $git_user && | ||
git config --global user.email $git_email | ||
- name: Version bump | ||
run: | | ||
set -euo pipefail | ||
current="$(sed -ne 's/^VERSION=\([0-9\.]*\).*$/\1/p' <Makefile)" | ||
bump="$(( ${current##*.} + 1))" | ||
prefix="${current%.*}" | ||
sed -e 's/^\(VERSION=\)[0-9\.]*/\1'"${prefix}.${bump}"'/g' -i Makefile | ||
git commit -m 'version bump' Makefile | ||
- name: Push develop | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.DUPLO_GITHUB_TOKEN }} | ||
branch: develop |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Start Release | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: 'Override Version' | ||
required: false | ||
default: '' # default to current version | ||
env: | ||
git_user: duplo-bot | ||
git_email: [email protected] | ||
jobs: | ||
start-release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: develop # Always release from develop | ||
fetch-depth: 0 | ||
persist-credentials: false # Needed so we can push with different credentials. | ||
# NOTE: Pushing with different credentials allows admins to push protected branches. | ||
# NOTE: Pushing with different credentials allow workflows to trigger from the push. | ||
|
||
# GET THE RELEASE VERSION | ||
- name: Get release version | ||
id: version | ||
run: | | ||
# Fail on errors | ||
set -euo pipefail | ||
# Use the current version if it is not being overridden | ||
if [ -z "${{ github.event.inputs.version }}" ]; then | ||
echo "::set-output name=release::$(sed -ne 's/^VERSION=\([0-9\.]*\).*$/\1/p' <Makefile)" | ||
# Otherwise, the use the overridden version. | ||
else | ||
echo "::set-output name=release::${{ github.event.inputs.version }}" | ||
fi | ||
# START THE RELEASE | ||
- name: Initialize mandatory git config | ||
run: | | ||
git config --global user.name $git_user && | ||
git config --global user.email $git_email | ||
- name: Start gitflow release | ||
uses: duplocloud/ghactions-start-gitflow-release@master | ||
with: | ||
github_token: ${{ secrets.DUPLO_GITHUB_TOKEN }} | ||
version: "${{ steps.version.outputs.release }}" | ||
precommit_run: | | ||
# Fail on errors | ||
set -euo pipefail | ||
if [ -z "${{ github.event.inputs.version }}" ]; then | ||
RELEASE_VERSION="${{ steps.version.outputs.release }}" | ||
sed -e 's/^\(VERSION=\)[0-9\.]*/\1'"$RELEASE_VERSION"'/g' -i Makefile | ||
fi |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
VERSION=0.3.0 | ||
VERSION=0.3.1 | ||
|
||
default: all | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
) | ||
|
||
var cacheDir string | ||
var noCache *bool | ||
|
||
// mustInitCache initializes the cacheDir or panics. | ||
func mustInitCache() { | ||
var err error | ||
|
||
if *noCache { | ||
return | ||
} | ||
|
||
cacheDir, err = os.UserCacheDir() | ||
dieIf(err, "cannot find cache directory") | ||
cacheDir = filepath.Join(cacheDir, "duplo-aws-credential-process") | ||
err = os.MkdirAll(cacheDir, 0700) | ||
dieIf(err, "cannot create cache directory") | ||
} | ||
|
||
// cacheReadUnmarshal reads JSON and unmarshals into the target, returning true on success. | ||
func cacheReadUnmarshal(file string, target interface{}) bool { | ||
|
||
if !*noCache && cacheDir != "" { | ||
file = filepath.Join(cacheDir, file) | ||
bytes, err := os.ReadFile(file) | ||
|
||
if err == nil { | ||
err = json.Unmarshal(bytes, target) | ||
if err == nil { | ||
return true | ||
} | ||
|
||
log.Printf("warning: %s: invalid JSON in cache: %s", file, err) | ||
} else if !errors.Is(err, os.ErrNotExist) { | ||
log.Printf("warning: %s: unable to read from cache", file) | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
// cacheWriteMustMarshal unmarshals the source and writes JSON. | ||
// It returns the JSON bytes and ignores cache write failures. | ||
func cacheWriteMustMarshal(file string, source interface{}) []byte { | ||
|
||
// Convert the source to JSON | ||
json, err := json.Marshal(source) | ||
dieIf(err, "cannot marshal to JSON") | ||
|
||
// Cache the JSON | ||
if !*noCache { | ||
file = filepath.Join(cacheDir, file) | ||
|
||
err = os.WriteFile(file, json, 0600) | ||
if err != nil { | ||
log.Printf("warning: %s: unable to write to cache", file) | ||
} | ||
} | ||
|
||
return json | ||
} | ||
|
||
// cacheGetAwsConfigOutput tries to read prior AWS creds fromt the cache. | ||
func cacheGetAwsConfigOutput(cacheKey string) (creds *AwsConfigOutput) { | ||
var file string | ||
|
||
// Read credentials from the cache. | ||
if !*noCache { | ||
file = fmt.Sprintf("%s,aws-creds.json", cacheKey) | ||
creds = &AwsConfigOutput{} | ||
if !cacheReadUnmarshal(file, creds) { | ||
creds = nil | ||
} | ||
} | ||
|
||
// Check credentials for expiry. | ||
if creds != nil { | ||
five_minutes_from_now := time.Now().UTC().Add(5 * time.Minute) | ||
expiration, err := time.Parse(time.RFC3339, creds.Expiration) | ||
|
||
// Invalid expiration? | ||
if err != nil { | ||
log.Printf("warning: %s: invalid Expiration time in credentials cache: %s", cacheKey, creds.Expiration) | ||
creds = nil | ||
|
||
// Expires in five minutes or less? | ||
} else if five_minutes_from_now.After(expiration) { | ||
creds = nil | ||
} | ||
} | ||
|
||
// Clear the cache if the creds expired. | ||
if creds == nil && file != "" { | ||
err := os.Remove(file) | ||
if err != nil && !errors.Is(err, os.ErrNotExist) { | ||
log.Printf("warning: %s: unable to remove from credentials cache", cacheKey) | ||
} | ||
} | ||
|
||
return | ||
} |
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
Oops, something went wrong.