Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: update release workflows #1019

Merged
merged 11 commits into from
Jan 31, 2024
42 changes: 42 additions & 0 deletions .github/workflows/build-images.reusable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build and Push Docker Image

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

jobs:
build-and-push-image:
name: Build and Push Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "16"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.IOTALEDGER_DOCKER_USERNAME }}
password: ${{ secrets.IOTALEDGER_DOCKER_PASSWORD }}

- name: Build and push Docker image for ${{ inputs.directory }}
uses: docker/build-push-action@v2
with:
context: ./${{ inputs.directory }}
file: ./${{ inputs.directory }}/Dockerfile
push: true
tags: ${{ inputs.image_tags }}
no-cache: true
37 changes: 0 additions & 37 deletions .github/workflows/build.yaml

This file was deleted.

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
72 changes: 0 additions & 72 deletions .github/workflows/nova-docker-deploy.yaml

This file was deleted.

58 changes: 58 additions & 0 deletions .github/workflows/release-production.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Release Explorer to Production

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- "!v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+"

jobs:
set_tags:
name: Set Tags
runs-on: ubuntu-latest
outputs:
version_tag: ${{ steps.set_version_tag.outputs.version_tag }}
steps:
- name: Set up the version tag for docker images
id: set_version_tag
run: |
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:
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:
name: Deploy Production to Server
needs: [set_tags, use-reusable-workflow]
runs-on: ubuntu-latest
strategy:
matrix:
environment: [prod, shimmer-prod]
steps:
- name: Add SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.UPDATER_SSH_PRIVATE_KEY }}

- 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 }}
71 changes: 71 additions & 0 deletions .github/workflows/release-staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Release Explorer to Staging

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+" # Versioning pattern 'v1.0.0-rc.0'
workflow_dispatch:
inputs:
tag:
description: "Tag"
required: true
default: "v1.0.0-rc.0"

jobs:
set_tags:
name: Set Tags
runs-on: ubuntu-latest
outputs:
version_tag: ${{ steps.set_version_tag.outputs.version_tag }}
steps:
- name: Checkout
uses: actions/checkout@v2

# If the workflow was triggered by a tag, use the tag as the version.
# Otherwise, use the tag from the workflow_dispatch event.
- name: Set up the version tag for docker images
id: set_version_tag
run: |
if [ "${{ github.event_name }}" = "push" ]; then
echo "VERSION_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "VERSION_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
fi

use-reusable-workflow:
strategy:
matrix:
directory: [api, client]
name: Build Image
needs: set_tags
uses: ./.github/workflows/build-images.reusable.yaml
with:
directory: ${{ matrix.directory }}
image_tags: |
iotaledger/explorer-${{ matrix.directory }}:${{ needs.set_tags.outputs.version_tag }}
secrets: inherit

deploy_to_server:
name: Deploy Staging to Server
needs: [set_tags, use-reusable-workflow]
runs-on: ubuntu-latest
strategy:
matrix:
environment: [staging, shimmer-staging]
steps:
- name: Add SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.UPDATER_SSH_PRIVATE_KEY }}

- 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 }}
Loading