feat(ci): semantic releases from develop branch #7
Workflow file for this run
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
name: Semantic Release | |
on: | |
push: | |
branches: | |
- main | |
- develop | |
pull_request: | |
branches: | |
- main | |
- develop | |
env: | |
IMAGE_NAMESPACE: "dominikpinsel" | |
IMAGE_NAME: "sandbox" | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: read | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Setup JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Execute Gradle build | |
run: ./gradlew build -PgithubToken=${{ secrets.GITHUB_TOKEN }} | |
semantic_release: | |
name: Repository Release | |
needs: build | |
runs-on: ubuntu-latest | |
permissions: | |
# see https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs | |
contents: write | |
pull-requests: write | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Setup Helm | |
uses: azure/setup-helm@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: 18 # Replace with your desired Node.js version | |
- name: Run semantic release | |
if: github.event_name != 'pull_request' | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
npx --yes -p @semantic-release/exec -p @semantic-release/changelog -p @semantic-release/git -p @semantic-release/commit-analyzer -p @semantic-release/release-notes-generator semantic-release | |
- name: Run semantic release | |
if: github.event_name == 'pull_request' | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
npx --yes -p @semantic-release/exec -p @semantic-release/github -p @semantic-release/changelog -p @semantic-release/git -p @semantic-release/commit-analyzer -p @semantic-release/release-notes-generator semantic-release --dry-run | |
docker: | |
name: Docker Release | |
needs: semantic_release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
# Create SemVer or ref tags dependent of trigger event | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: | | |
${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }} | |
# Automatically prepare image tags; See action docs for more examples. | |
# semver patter will generate tags like these for example :1 :1.2 :1.2.3 | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}} | |
type=semver,pattern={{major}}.{{minor}} | |
- name: DockerHub login | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v2 | |
with: | |
# Use existing DockerHub credentials present as secrets | |
username: ${{ secrets.DOCKER_HUB_USER }} | |
password: ${{ secrets.DOCKER_HUB_TOKEN }} | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Setup JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Execute Gradle build | |
run: ./gradlew build -PgithubToken=${{ secrets.GITHUB_TOKEN }} | |
- name: Build Docker image | |
run: docker build -t ${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}:latest . | |
- name: Log in to the Container registry | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_HUB_USER }} | |
password: ${{ secrets.DOCKER_HUB_TOKEN }} | |
- name: Extract new app version from Chart.yaml | |
run: | | |
chart_yaml_path="./charts/managed-identity-wallet/Chart.yaml" | |
# Use grep to find the line containing appVersion, awk to split by ":" and cut to remove leading/trailing spaces | |
app_version=$(grep 'appVersion:' "$chart_yaml_path" | awk -F: '{gsub(/^[ \t]+|[ \t]+$/,"", $2); print $2}') | |
echo "RELEASE_VERSION=$app_version" >> $GITHUB_ENV | |
- name: Extract new image release version from Chart.yaml | |
if: github.ref == 'refs/heads/main' | |
run: | | |
echo "IMAGE_VERSION={{ env.RELEASE_VERSION }}" >> $GITHUB_ENV | |
echo "LATEST_IMAGE_TAG=latest" >> $GITHUB_ENV | |
- name: Extract new image pre-release version from Chart.yaml | |
if: github.ref != 'refs/heads/main' | |
run: | | |
echo "IMAGE_VERSION={{ env.RELEASE_VERSION }}" >> $GITHUB_ENV | |
echo "LATEST_IMAGE_TAG=alpha" >> $GITHUB_ENV | |
- name: Push image | |
if: github.event_name != 'pull_request' | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ env.LATEST_IMAGE_TAG }} | |
${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_VERSION }} | |
labels: | | |
org.opencontainers.image.source=${{ github.event.repository.html_url }} | |
org.opencontainers.image.created=${{ steps.prep.outputs.created }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.version=${{ env.RELEASE_VERSION }} | |
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }} | |
org.opencontainers.image.title=${{ github.event.repository.name }} | |
org.opencontainers.image.description=${{ github.event.repository.description }} | |
org.opencontainers.image.url=${{ github.event.repository.html_url }} | |
org.opencontainers.image.documentation=${{ github.event.repository.html_url }}/blob/${{ github.ref }}/README.md | |
org.opencontainers.image.authors=${{ github.event.repository.owner.login }} | |
# https://github.com/peter-evans/dockerhub-description | |
# Important step to push image description to DockerHub | |
- name: Update Docker Hub description | |
if: github.event_name != 'pull_request' | |
uses: peter-evans/dockerhub-description@v3 | |
with: | |
# readme-filepath defaults to toplevel README.md, Only necessary if you have a dedicated file with your 'Notice for docker images' | |
readme-filepath: Docker-hub-notice.md | |
username: ${{ secrets.DOCKER_HUB_USER }} | |
password: ${{ secrets.DOCKER_HUB_TOKEN }} | |
repository: ${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }} | |
helm: | |
name: Helm Release | |
needs: semantic_release | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Install Helm | |
uses: azure/setup-helm@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Add Helm dependency repositories | |
run: | | |
helm repo add bitnami https://charts.bitnami.com/bitnami | |
- name: Configure Git | |
run: | | |
git config user.name "$GITHUB_ACTOR" | |
git config user.email "$GITHUB_ACTOR@users.noreply.github.com" | |
- name: Run chart-releaser | |
if: github.event_name != 'pull_request' | |
uses: helm/chart-releaser-action@v1.4.1 | |
env: | |
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | |
github: | |
name: Github Release | |
needs: semantic_release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Extract new app version from Chart.yaml | |
run: | | |
chart_yaml_path="./charts/managed-identity-wallet/Chart.yaml" | |
# Use grep to find the line containing appVersion, awk to split by ":" and cut to remove leading/trailing spaces | |
app_version=$(grep 'appVersion:' "$chart_yaml_path" | awk -F: '{gsub(/^[ \t]+|[ \t]+$/,"", $2); print $2}') | |
echo "RELEASE_VERSION=$app_version" >> $GITHUB_ENV | |
- name: Create Release Tag | |
uses: thomaseizinger/create-release@1.0.0 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
target_commitish: ${{ github.event.pull_request.merge_commit_sha }} | |
tag_name: ${{ env.RELEASE_VERSION }} | |
name: ${{ env.RELEASE_VERSION }} | |
draft: false | |
prerelease: false |