Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

Release

Release #27

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
prerelease:
description: 'Create a new prerelease'
type: boolean
default: true
jobs:
create-new-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.ACTIONS_PUSH_TO_PROTECTED_BRANCH }}
- uses: actions/setup-node@v3
with:
node-version: 14
- name: Configure Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Set Prerelease Tag
id: set_prerelease_tag
run: |
# Get branch name
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//-/g')
# Set it as an output (optional, if you want to use it in a later step)
echo "PRERELEASE_TAG=$BRANCH_NAME" >> $GITHUB_OUTPUT
- name: Bump and Commit
run: |
if [[ "${{ github.event.inputs.prerelease }}" == "true" ]]; then
npx standard-version --prerelease ${{ steps.set_prerelease_tag.outputs.PRERELEASE_TAG }}
else
npx standard-version
fi
git push --follow-tags
push:
needs: create-new-release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
environment: docker
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.ref }}
# Get version from package.json
- name: Get version from package.json
id: version
run: echo "version=$(cat package.json | jq -r '.version')" >> $GITHUB_OUTPUT
# Build the Docker image
- name: Build Docker image
run: docker build --cache-from democracy/democracy-app.de:latest -t democracy/democracy-app.de:${{ steps.version.outputs.version }} .
# Push the image to Docker Hub
- name: Push image to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push to Docker Hub
run: |
docker tag democracy/democracy-app.de:${{ steps.version.outputs.version }} democracy/democracy-app.de:latest
if [ "${{ github.event.inputs.prerelease }}" != "true" ]; then
docker push democracy/democracy-app.de:latest
fi
docker push democracy/democracy-app.de:${{ steps.version.outputs.version }}
create-pull-request-to-infrastructure:
needs: push
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository where the pull request should be created
- name: Checkout target repository
uses: actions/checkout@v3
with:
repository: demokratie-live/infrastructure
token: ${{ secrets.ACTION_INFRASTRUCTURE_PR }}
fetch-depth: 0
ref: main
- name: Configure Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Step 2: Create a new Branch
- name: Create a new branch
run: |
git checkout -b democracy-app.de-${{ needs.push.outputs.version }}
git push --set-upstream origin democracy-app.de-${{ needs.push.outputs.version }}
- name: Edit file
run: |
sed -i -E "s/image: democracy\/democracy-app.de:.*$/image: democracy\/democracy-app.de:${{ needs.push.outputs.version }}/g" kustomize/base/main/democracy-app-depl.yaml
git add kustomize/base/main/democracy-app-depl.yaml
git commit -m "chore(infrastructure): update Docker container version in Kubernetes YAML"
git push --set-upstream origin democracy-app.de-${{ needs.push.outputs.version }}
# Step 4: Create the pull request
- name: Create Pull Request
uses: octokit/request-action@v2.x
with:
route: POST /repos/{owner}/{repo}/pulls
owner: "demokratie-live"
repo: infrastructure
title: "New version for democracy-app.de ${{ needs.push.outputs.version }}"
base: main
head: democracy-app.de-${{ needs.push.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.ACTION_INFRASTRUCTURE_PR }}