Skip to content

Commit

Permalink
feat: add reusable workflow to create a release (#1026)
Browse files Browse the repository at this point in the history
* feat: add reusable workflow to create a release

* feat: improve and add changelog to automatic deploy (#1028)
  • Loading branch information
VmMad authored Jan 30, 2024
1 parent 56e58bd commit 2868e5e
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 30 deletions.
27 changes: 9 additions & 18 deletions .github/workflows/build-images.reusable.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: Build and Push Images
name: Build and Push Docker Image

on:
workflow_call:
inputs:
api_image_tags:
directory:
required: true
type: string
client_image_tags:
image_tags:
required: true
type: string

jobs:
build-and-push-images:
name: Build and Push Docker Images
build-and-push-image:
name: Build and Push Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -32,20 +32,11 @@ jobs:
username: ${{ secrets.IOTALEDGER_DOCKER_USERNAME }}
password: ${{ secrets.IOTALEDGER_DOCKER_PASSWORD }}

- name: Build and push API Docker image
- name: Build and push Docker image for ${{ inputs.directory }}
uses: docker/build-push-action@v2
with:
context: ./api
file: ./api/Dockerfile
context: ./${{ inputs.directory }}
file: ./${{ inputs.directory }}/Dockerfile
push: true
tags: ${{ inputs.api_image_tags }}
no-cache: true

- name: Build and push Client Docker image
uses: docker/build-push-action@v2
with:
context: ./client
file: ./client/Dockerfile
push: true
tags: ${{ inputs.client_image_tags }}
tags: ${{ inputs.image_tags }}
no-cache: true
75 changes: 75 additions & 0 deletions .github/workflows/create-draft-release.reusable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Create Draft Release

on:
workflow_call:
inputs:
name:
required: true
type: string
version_tag:
required: true
type: string

jobs:
github_draft_release:
name: Create Draft Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Prepare repository tags
run: |
if git rev-parse --is-shallow-repository | grep -q 'true'; then
git fetch --prune --unshallow --tags -f
else
git fetch --prune --tags -f
fi
- name: Build changelog
id: build_changelog
run: |
echo "Building changelog..."
# Create a changelog file with a header:
echo "# Changelog" > CHANGELOG.md
# Check repository tags and the last tagged commit
n_tags=`git tag -l 'v*' --sort=-v:refname | wc -l`
prev_tag=`git tag -l 'v*' --sort=-v:refname | sed '2q;d'`
if [ $n_tags -eq 1 ]; then
last_commit=`git rev-list --max-parents=0 HEAD`
else
last_commit=`git rev-list -n 1 $prev_tag`
fi
# Fill the changelog file with the commits since the last tag
# Set max tries to equal the maximum number of commits as protection
max_tries=`git rev-list --count HEAD`
i=0
while [ `git rev-parse HEAD~$i` != $last_commit ] && [ $i -lt $((max_tries-1)) ]
do
echo '- ' `git show -s --format=%s HEAD~$i` >> CHANGELOG.md
i=$((i+1))
done
# Set the complete changelog url
echo >> CHANGELOG.md
compare=""
if [ $n_tags -eq 1 ]; then
compare=$last_commit
else
compare=$prev_tag
fi
compare="${compare}...`git tag -l 'v*' --sort=-v:refname | sed '1q;d'`"
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${compare}" >> CHANGELOG.md
echo "Changelog built successfully."
- name: Create Draft Release
uses: softprops/action-gh-release@v1
with:
name: ${{ inputs.name }}
tag_name: ${{ inputs.version_tag }}
draft: true
body_path: CHANGELOG.md
22 changes: 15 additions & 7 deletions .github/workflows/release-production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ jobs:
echo "VERSION_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
use-reusable-workflow:
strategy:
matrix:
directory: [api, client]
name: Build Images
needs: set_tags
uses: ./.github/workflows/build-images.reusable.yaml
with:
api_image_tags: |
iotaledger/explorer-api:${{ needs.set_tags.outputs.version_tag }}
iotaledger/explorer-api:latest
client_image_tags: |
iotaledger/explorer-client:${{ needs.set_tags.outputs.version_tag }}
iotaledger/explorer-client:latest
directory: ${{ matrix.directory }}
image_tags: |
iotaledger/explorer-${{ matrix.directory }}:${{ needs.set_tags.outputs.version_tag }}
iotaledger/explorer-${{ matrix.directory }}:latest
secrets: inherit

deploy_to_server:
Expand All @@ -48,3 +48,11 @@ jobs:
- name: Deploy to Server
run: |
ssh -o StrictHostKeyChecking=no updater@${{ secrets.EXPLORER_GATEWAY }} "${{ matrix.environment }} ${{ needs.set_tags.outputs.version_tag }}"
create_draft_release:
name: Create Draft Release
needs: [set_tags, use-reusable-workflow, deploy_to_server]
uses: ./.github/workflows/create-draft-release.reusable.yaml
with:
name: Explorer ${{ needs.set_tags.outputs.version_tag }}
version_tag: ${{ needs.set_tags.outputs.version_tag }}
20 changes: 15 additions & 5 deletions .github/workflows/release-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ jobs:
fi
use-reusable-workflow:
name: Build Images
strategy:
matrix:
directory: [api, client]
name: Build Image
needs: set_tags
uses: ./.github/workflows/build-images.reusable.yaml
with:
api_image_tags: |
iotaledger/explorer-api:${{ needs.set_tags.outputs.version_tag }}
client_image_tags: |
iotaledger/explorer-client:${{ needs.set_tags.outputs.version_tag }}
directory: ${{ matrix.directory }}
image_tags: |
iotaledger/explorer-${{ matrix.directory }}:${{ needs.set_tags.outputs.version_tag }}
secrets: inherit

deploy_to_server:
Expand All @@ -59,3 +61,11 @@ jobs:
- name: Deploy to Server
run: |
ssh -o StrictHostKeyChecking=no updater@${{ secrets.EXPLORER_GATEWAY }} "${{ matrix.environment }} ${{ needs.set_tags.outputs.version_tag }}"
create_draft_release:
name: Create Draft Release
needs: [set_tags, use-reusable-workflow, deploy_to_server]
uses: ./.github/workflows/create-draft-release.reusable.yaml
with:
name: Explorer ${{ needs.set_tags.outputs.version_tag }}
version_tag: ${{ needs.set_tags.outputs.version_tag }}

0 comments on commit 2868e5e

Please sign in to comment.