Skip to content

Commit

Permalink
Merge pull request #9 from leojonathanoh/enhancement/ci-use-only-mast…
Browse files Browse the repository at this point in the history
…er-pr-and-tag-refs-for-ci-pipeline

Enhancement (ci): Use only master pr and tag refs for ci pipeline
  • Loading branch information
leojonathanoh authored Nov 19, 2021
2 parents c2336cf + ef901e1 commit cb1b50b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 156 deletions.
1 change: 0 additions & 1 deletion .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# For Generate-DockerImageVariants: For CalVer releases. Each push to 'release' branch is a time-based release.
name-template: '$RESOLVED_VERSION 🌈'
tag-template: '$RESOLVED_VERSION'
categories:
Expand Down
91 changes: 18 additions & 73 deletions .github/workflows/ci-master-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ on:
push:
branches:
- master
- release # For Generate-DockerImageVariants: For CalVer releases. Each push to 'release' branch is a time-based release.
tags:
- '**'
pull_request:
branches:
- master
Expand All @@ -14,7 +15,6 @@ jobs:
runs-on: ubuntu-latest
env:
VARIANT_TAG: 4.1.4-ubuntu-16.04
# VARIANT_TAG_WITH_REF: 4.1.4-ubuntu-16.04-${GITHUB_REF}
VARIANT_BUILD_DIR: variants/4.1.4-ubuntu-16.04
steps:
- name: Checkout
Expand Down Expand Up @@ -60,11 +60,12 @@ jobs:
# CI_PROJECT_NAMESPACE=$( echo "${{ github.repository }}" | cut -d '/' -f 1 )
# CI_PROJECT_NAME=$( echo "${{ github.repository }}" | cut -d '/' -f 2 )
# Get 'ref-name' from 'refs/heads/ref-name'
# Get <branch_name> from refs/heads/<branch_name>, or <tag-name> from refs/tags/<tag_name>. E.g. . E.g. 'master', 'v1.2.3'
REF=$( echo "${GITHUB_REF}" | rev | cut -d '/' -f 1 | rev )
# Get commit hash E.g. 'b29758a'
SHA_SHORT=$( echo "${GITHUB_SHA}" | cut -c1-7 )
# For Generate-DockerImageVariants: Generate the final tags. E.g. 'master-v1.0.0-alpine' and 'master-b29758a-v1.0.0-alpine'
# Generate the final tags. E.g. 'master-v1.0.0-alpine' and 'master-b29758a-v1.0.0-alpine'
VARIANT_TAG_WITH_REF="${REF}-${VARIANT_TAG}"
VARIANT_TAG_WITH_REF_AND_SHA_SHORT="${REF}-${SHA_SHORT}-${VARIANT_TAG}"
Expand All @@ -74,14 +75,13 @@ jobs:
# echo "::set-output name=REF::$REF"
# echo "::set-output name=SHA_SHORT::$SHA_SHORT"
# echo "::set-output name=REF_AND_SHA_SHORT::$REF_AND_SHA_SHORT"
# For Generate-DockerImageVariants: Set step output(s)
echo "::set-output name=CONTEXT::$VARIANT_BUILD_DIR"
echo "::set-output name=VARIANT_TAG::$VARIANT_TAG"
echo "::set-output name=VARIANT_TAG_WITH_REF::$VARIANT_TAG_WITH_REF"
echo "::set-output name=VARIANT_TAG_WITH_REF_AND_SHA_SHORT::$VARIANT_TAG_WITH_REF_AND_SHA_SHORT"
- name: Login to docker registry
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
run: echo "${DOCKERHUB_REGISTRY_PASSWORD}" | docker login -u "${DOCKERHUB_REGISTRY_USER}" --password-stdin
env:
DOCKERHUB_REGISTRY_USER: ${{ secrets.DOCKERHUB_REGISTRY_USER }}
Expand Down Expand Up @@ -118,9 +118,7 @@ jobs:

- name: Build and push (release)
id: docker_build_release
# For Generate-DockerImageVariants: For CalVer releases. Each push to 'release' branch is a time-based release.
# if: startsWith(github.ref, 'refs/tags/')
if: github.ref == 'refs/heads/release'
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v2
with:
context: ${{ steps.prep.outputs.CONTEXT }}
Expand All @@ -141,91 +139,38 @@ jobs:
run: docker logout
if: always()

# For Generate-DockerImageVariants: For CalVer releases. Each push to 'release' branch is a time-based release.
converge-master-and-release-branches:
needs: [build-4-1-4-ubuntu-16-04]
if: github.ref == 'refs/heads/release'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Merge release into master (fast-forward)
run: |
git checkout master
git merge release
git push origin master
# For Generate-DockerImageVariants: For CalVer releases. Each push to 'release' branch is a time-based release.
resolve-release-tag:
runs-on: ubuntu-latest
outputs:
TAG: ${{ steps.resolve-release-tag.outputs.TAG }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Resolve release tag
id: resolve-release-tag
run: |
set +e
# E.g. 20210402
TODAYS_DATE=$( date -u '+%Y%m%d' )
# Is this the first tag for this date?
TODAYS_DATE_TAGS=$( git tag --list | grep "^$TODAYS_DATE" )
TAG=
if [ -z "$TODAYS_DATE_TAGS" ]; then
# E.g. 20210402.0.0
TAG="$TODAYS_DATE.0.0" # Send this to stdout
else
# E.g. if there are 20210402.0.0, 20210402.0.1, 20210402.0.2, this returns 2
VERSION_MINOR_LATEST=$( echo "$TODAYS_DATE_TAGS" | cut -d '.' -f 3 | sort -nr | head -n1 )
# Minor version
VERSION_MINOR=$( expr "$VERSION_MINOR_LATEST" + 1 )
# E.g. 20210402.0.3
TAG="$TODAYS_DATE.0.$VERSION_MINOR" # Send this to stdout
fi
echo "TODAYS_DATE: $TODAYS_DATE"
echo "TODAYS_DATE_TAGS: $TODAYS_DATE_TAGS"
echo "TAG: $TAG"
echo "::set-output name=TAG::$TAG"
- name: Print outputs
run: echo ${{ steps.resolve-release-tag.outputs.TAG }}

update-draft-release:
needs: [build-4-1-4-ubuntu-16-04, resolve-release-tag]
needs: [build-4-1-4-ubuntu-16-04]
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Print inputs
run: echo ${{ needs.resolve-release-tag.outputs.TAG }}
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter.yml
publish: false
name: ${{ needs.resolve-release-tag.outputs.TAG }}
tag: ${{ needs.resolve-release-tag.outputs.TAG }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-draft-release:
needs: [build-4-1-4-ubuntu-16-04, converge-master-and-release-branches, resolve-release-tag]
# For Generate-DockerImageVariants: For CalVer releases. Each push to 'release' branch is a time-based release.
# if: startsWith(github.ref, 'refs/tags/')
if: github.ref == 'refs/heads/release'
needs: [build-4-1-4-ubuntu-16-04]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Resolve tag
id: resolve-tag
run: |
# Get <branch_name> from refs/heads/<branch_name>, or <tag-name> from refs/tags/<tag_name>. E.g. . E.g. 'master', 'v1.2.3'
REF=$( echo "${GITHUB_REF}" | rev | cut -d '/' -f 1 | rev )
echo "::set-output name=REF::$REF"
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter.yml
publish: true
name: ${{ needs.resolve-release-tag.outputs.TAG }}
tag: ${{ needs.resolve-release-tag.outputs.TAG }}
name: ${{ steps.resolve-tag.outputs.REF }}
tag: ${{ steps.resolve-tag.outputs.REF }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 0 additions & 1 deletion generate/templates/.github/release-drafter.yml.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@'
# For Generate-DockerImageVariants: For CalVer releases. Each push to 'release' branch is a time-based release.
name-template: '$RESOLVED_VERSION 🌈'
tag-template: '$RESOLVED_VERSION'
categories:
Expand Down
99 changes: 18 additions & 81 deletions generate/templates/.github/workflows/ci-master-pr.yml.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ on:
push:
branches:
- master
- release # For Generate-DockerImageVariants: For CalVer releases. Each push to 'release' branch is a time-based release.
tags:
- '**'
pull_request:
branches:
- master
Expand All @@ -21,7 +22,6 @@ $VARIANTS | % {
runs-on: ubuntu-latest
env:
VARIANT_TAG: $( $_['tag'] )
# VARIANT_TAG_WITH_REF: $( $_['tag'] )-`${GITHUB_REF}
VARIANT_BUILD_DIR: $( $_['build_dir_rel'] )
"@
@'
Expand Down Expand Up @@ -70,11 +70,12 @@ $VARIANTS | % {
# CI_PROJECT_NAMESPACE=$( echo "${{ github.repository }}" | cut -d '/' -f 1 )
# CI_PROJECT_NAME=$( echo "${{ github.repository }}" | cut -d '/' -f 2 )
# Get 'ref-name' from 'refs/heads/ref-name'
# Get <branch_name> from refs/heads/<branch_name>, or <tag-name> from refs/tags/<tag_name>. E.g. . E.g. 'master', 'v1.2.3'
REF=$( echo "${GITHUB_REF}" | rev | cut -d '/' -f 1 | rev )
# Get commit hash E.g. 'b29758a'
SHA_SHORT=$( echo "${GITHUB_SHA}" | cut -c1-7 )
# For Generate-DockerImageVariants: Generate the final tags. E.g. 'master-v1.0.0-alpine' and 'master-b29758a-v1.0.0-alpine'
# Generate the final tags. E.g. 'master-v1.0.0-alpine' and 'master-b29758a-v1.0.0-alpine'
VARIANT_TAG_WITH_REF="${REF}-${VARIANT_TAG}"
VARIANT_TAG_WITH_REF_AND_SHA_SHORT="${REF}-${SHA_SHORT}-${VARIANT_TAG}"
Expand All @@ -84,14 +85,13 @@ $VARIANTS | % {
# echo "::set-output name=REF::$REF"
# echo "::set-output name=SHA_SHORT::$SHA_SHORT"
# echo "::set-output name=REF_AND_SHA_SHORT::$REF_AND_SHA_SHORT"
# For Generate-DockerImageVariants: Set step output(s)
echo "::set-output name=CONTEXT::$VARIANT_BUILD_DIR"
echo "::set-output name=VARIANT_TAG::$VARIANT_TAG"
echo "::set-output name=VARIANT_TAG_WITH_REF::$VARIANT_TAG_WITH_REF"
echo "::set-output name=VARIANT_TAG_WITH_REF_AND_SHA_SHORT::$VARIANT_TAG_WITH_REF_AND_SHA_SHORT"
- name: Login to docker registry
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
run: echo "${DOCKERHUB_REGISTRY_PASSWORD}" | docker login -u "${DOCKERHUB_REGISTRY_USER}" --password-stdin
env:
DOCKERHUB_REGISTRY_USER: ${{ secrets.DOCKERHUB_REGISTRY_USER }}
Expand Down Expand Up @@ -131,9 +131,7 @@ $VARIANTS | % {
- name: Build and push (release)
id: docker_build_release
# For Generate-DockerImageVariants: For CalVer releases. Each push to 'release' branch is a time-based release.
# if: startsWith(github.ref, 'refs/tags/')
if: github.ref == 'refs/heads/release'
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v2
with:
context: `${{ steps.prep.outputs.CONTEXT }}
Expand Down Expand Up @@ -165,88 +163,23 @@ if ( $_['tag_as_latest'] ) {
'@
}

@"
# For Generate-DockerImageVariants: For CalVer releases. Each push to 'release' branch is a time-based release.
converge-master-and-release-branches:
needs: [$( $local:WORKFLOW_JOB_NAMES -join ', ' )]
if: github.ref == 'refs/heads/release'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Merge release into master (fast-forward)
run: |
git checkout master
git merge release
git push origin master
"@

@'
# For Generate-DockerImageVariants: For CalVer releases. Each push to 'release' branch is a time-based release.
resolve-release-tag:
runs-on: ubuntu-latest
outputs:
TAG: ${{ steps.resolve-release-tag.outputs.TAG }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Resolve release tag
id: resolve-release-tag
run: |
set +e
# E.g. 20210402
TODAYS_DATE=$( date -u '+%Y%m%d' )
# Is this the first tag for this date?
TODAYS_DATE_TAGS=$( git tag --list | grep "^$TODAYS_DATE" )
TAG=
if [ -z "$TODAYS_DATE_TAGS" ]; then
# E.g. 20210402.0.0
TAG="$TODAYS_DATE.0.0" # Send this to stdout
else
# E.g. if there are 20210402.0.0, 20210402.0.1, 20210402.0.2, this returns 2
VERSION_MINOR_LATEST=$( echo "$TODAYS_DATE_TAGS" | cut -d '.' -f 3 | sort -nr | head -n1 )
# Minor version
VERSION_MINOR=$( expr "$VERSION_MINOR_LATEST" + 1 )
# E.g. 20210402.0.3
TAG="$TODAYS_DATE.0.$VERSION_MINOR" # Send this to stdout
fi
echo "TODAYS_DATE: $TODAYS_DATE"
echo "TODAYS_DATE_TAGS: $TODAYS_DATE_TAGS"
echo "TAG: $TAG"
echo "::set-output name=TAG::$TAG"
- name: Print outputs
run: echo ${{ steps.resolve-release-tag.outputs.TAG }}
'@

@"
update-draft-release:
needs: [$( $local:WORKFLOW_JOB_NAMES -join ', ' ), resolve-release-tag]
needs: [$( $local:WORKFLOW_JOB_NAMES -join ', ' )]
"@
@'
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Print inputs
run: echo ${{ needs.resolve-release-tag.outputs.TAG }}
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter.yml
publish: false
name: ${{ needs.resolve-release-tag.outputs.TAG }}
tag: ${{ needs.resolve-release-tag.outputs.TAG }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
'@
Expand All @@ -255,23 +188,27 @@ if ( $_['tag_as_latest'] ) {
publish-draft-release:
needs: [$( $local:WORKFLOW_JOB_NAMES -join ', ' ), converge-master-and-release-branches, resolve-release-tag]
needs: [$( $local:WORKFLOW_JOB_NAMES -join ', ' )]
"@
@'
# For Generate-DockerImageVariants: For CalVer releases. Each push to 'release' branch is a time-based release.
# if: startsWith(github.ref, 'refs/tags/')
if: github.ref == 'refs/heads/release'
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Resolve tag
id: resolve-tag
run: |
# Get <branch_name> from refs/heads/<branch_name>, or <tag-name> from refs/tags/<tag_name>. E.g. . E.g. 'master', 'v1.2.3'
REF=$( echo "${GITHUB_REF}" | rev | cut -d '/' -f 1 | rev )
echo "::set-output name=REF::$REF"
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter.yml
publish: true
name: ${{ needs.resolve-release-tag.outputs.TAG }}
tag: ${{ needs.resolve-release-tag.outputs.TAG }}
name: ${{ steps.resolve-tag.outputs.REF }}
tag: ${{ steps.resolve-tag.outputs.REF }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down

0 comments on commit cb1b50b

Please sign in to comment.