Skip to content

Commit

Permalink
[feature] Release Actions Support für Repositories mit mehreren Proje…
Browse files Browse the repository at this point in the history
…kten.

ORG-254
  • Loading branch information
stefan-hoelzl committed Jun 13, 2024
1 parent b73d6bb commit 39711b0
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 171 deletions.
74 changes: 5 additions & 69 deletions .github/workflows/release-actions-create-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,74 +10,10 @@ jobs:
create-pr:
name: Create PR
runs-on: ubuntu-22.04
if: ${{ github.event_name == 'push' && contains(fromJson('["release-major", "release-minor", "release-patch"]'), github.ref_name) && !startsWith(github.event.head_commit.message, '[release]') }}
if: ${{ github.event_name == 'create' && startsWith(github.ref_name, 'release-') }}
steps:
- name: Check for latest template version
- name: UPDATE REQUIRED
run: |
expectedHash="${{ hashFiles('ci-scripts/templates/org-release-actions.yml') }}"
actualHash="${{ hashFiles('.github/workflows/org-release-actions.yml') }}"
if [[ "$expectedHash" != "$actualHash" ]]; then
echo "::error::Workflow org-release-actions.yml is outdated. Use the latest version from ci-scripts/templates in this project"
exit 1
fi
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.BALTECH_BOT_ID }}
private-key: ${{ secrets.BALTECH_BOT_KEY }}
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.generate-token.outputs.token }}
- name: Configure git
run: |
git config user.name "${{ github.event.pusher.name }}"
git config user.email "${{ github.event.pusher.email }}"
- name: Checkout ci-scripts repository
uses: actions/checkout@v4
with:
repository: baltech-ag/ci-scripts
ref: ${{ inputs.ci-scripts-ref }}
path: ci-scripts
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install tox
run: |
python -m pip install --upgrade pip
python -m pip install tox==3.28.0
- name: Restore tox environment from cache
id: tox-cache
uses: actions/cache@v4
with:
path: .tox
key: ${{ runner.os }}-tox-${{ hashFiles('tox.ini') }}-${{ hashFiles('poetry.lock') }}
- name: Recreate tox environment
if: steps.tox-cache.outputs.cache-hit != 'true'
run: tox --recreate --notest
- name: Update version
run: python ci-scripts/release_actions.py prepare-next-version
env:
CI_PROJECT_NAME: ${{ github.event.repository.name }}
CI_BRANCH_NAME: ${{ github.ref_name }}
- name: Create PR for release branch
run: |
BASE_BRANCH=$(python ci-scripts/release_actions.py print-base-branch)
PR_TITLE="[release] ${{ github.event.repository.name }} $(cat VERSION)"
gh pr create --base $BASE_BRANCH --head ${{ github.ref }} --title "$PR_TITLE" --body "" --assignee "${{ github.actor }}"
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Approve PR
run: gh pr review ${{ github.ref_name }} --approve
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Merge PR
run: gh pr merge ${{ github.ref_name }} --rebase --auto
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Cleanup
if: always()
run: rm -rf ci-scripts
echo "::error::Workflow org-release-actions.yml is outdated."
echo "::error::Please replace '.github/workflows/org-release-actions.yml' in this repository with 'templates/org-release-actions.yml' from the ci-scripts repository.'
exit 1
40 changes: 5 additions & 35 deletions .github/workflows/release-actions-create-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,10 @@ jobs:
create-tag:
name: Create tag
runs-on: ubuntu-22.04
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.merged == true && contains(fromJson('["release-major", "release-minor", "release-patch"]'), github.head_ref) }}
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.merged == true && startsWith(github.head_ref, 'release-') }}
steps:
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.BALTECH_BOT_ID }}
private-key: ${{ secrets.BALTECH_BOT_KEY }}
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ steps.generate-token.outputs.token }}
- name: Configure git
- name: UPDATE REQUIRED
run: |
git config user.name "${{ github.event.pusher.name }}"
git config user.email "${{ github.event.pusher.email }}"
- name: Checkout ci-scripts repository
uses: actions/checkout@v4
with:
repository: baltech-ag/ci-scripts
ref: ${{ inputs.ci-scripts-ref }}
path: ci-scripts
token: ${{ steps.generate-token.outputs.token }}
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Read VERSION file
id: version
run: echo "version=$(cat VERSION)" >> $GITHUB_OUTPUT
- name: Create tag on release commit
run: |
git tag v${{ steps.version.outputs.version }}
git push origin v${{ steps.version.outputs.version }}
- name: Cleanup
if: always()
run: rm -rf ci-scripts
echo "::error::Workflow org-release-actions.yml is outdated."
echo "::error::Please replace '.github/workflows/org-release-actions.yml' in this repository with 'templates/org-release-actions.yml' from the ci-scripts repository.'
exit 1
24 changes: 11 additions & 13 deletions .github/workflows/release-actions-deploy-fileserver.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
name: Release Actions - Deploy build to OneDrive
name: Release Actions - Deploy build to Fileserver
on:
workflow_call:
inputs:
artifact-name:
type: string
required: true
artifact-file-name:
type: string
required: true
projects-folder:
type: string
required: true
project-name:
type: string
required: true
file-extension:
version:
type: string
required: true
jobs:
deploy-onedrive:
name: Deploy build to OneDrive
runs-on: [self-hosted, windows, onedrive]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download artifact
id: download-artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ inputs.artifact-name }}
- name: Read project version
id: version
run: ("version=" + (Get-Content VERSION).replace(".", "_")) | Out-File -FilePath $env:GITHUB_OUTPUT -Append
- name: Get Artifact Infos
id: artifact
run: |
$artifact = (Get-ChildItem -Path "${{ steps.download-artifact.outputs.download-path }}")[0]
("path=" + $artifact.FullName) | Out-File -FilePath $env:GITHUB_OUTPUT -Append
("extension=" + $artifact.Extension) | Out-File -FilePath $env:GITHUB_OUTPUT -Append
- name: Deploy
shell: cmd
run: |
setlocal EnableDelayedExpansion
set "SOURCE=${{ steps.download-artifact.outputs.download-path }}\${{ inputs.artifact-file-name }}"
set "SOURCE=${{ steps.artifact.outputs.path }}"
echo Source file: !SOURCE!
set "DEST=%OneDriveCommercial%\F&E\Projekte\${{ inputs.projects-folder }}\${{ inputs.project-name }}\bin\${{ inputs.project-name }}_${{ steps.version.outputs.version }}${{ inputs.file-extension }}"
set "DEST=%OneDriveCommercial%\F&E\Projekte\${{ inputs.projects-folder }}\${{ inputs.project-name }}\bin\${{ inputs.project-name }}_${{ inputs.version }}${{ steps.artifact.outputs.extension }}"
echo Destination file: !DEST!
copy "!SOURCE!" "!DEST!"
168 changes: 168 additions & 0 deletions .github/workflows/release-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: Release Actions - Setup
on:
workflow_call:
inputs:
ci-scripts-ref:
type: string
required: false
default: master
check-template:
type: boolean
required: false
default: true
outputs:
release-stage:
description: "the current stage of the release process"
value: ${{ jobs.release-context.outputs.release-stage }}
deploy-mode:
description: "'release' or 'development'"
value: ${{ jobs.release-context.outputs.deploy-mode }}
project-name:
description: "project name"
value: ${{ jobs.release-context.outputs.project-name }}
project-id:
description: "sub project id"
value: ${{ jobs.release-context.outputs.project-id }}
version:
description: "the current project version"
value: ${{ jobs.release-context.outputs.version }}
version-file:
description: "version file containing the current version"
value: ${{ jobs.release-context.outputs.version-file }}

jobs:
release-context:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Checkout ci-scripts repository
uses: actions/checkout@v4
with:
repository: baltech-ag/ci-scripts
ref: ${{ inputs.ci-scripts-ref }}
path: ci-scripts
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Build Release Context
id: context
shell: pwsh
run:
echo '${{ toJSON(github) }}' # prints github-context for debugging purposes
python ci-scripts/release_actions.py `
print-release-context `
--event="${{ github.event_name }}" `
--ref="${{ github.head_ref || github.ref }}" `
--repository-name="${{ github.event.repository.name }}" `
| Out-File -FilePath $env:GITHUB_OUTPUT
Get-Content -Path $env:GITHUB_OUTPUT # prints output variables for debugging purposes
- name: Check for latest template version
if: ${{ inputs.check-template && steps.context.output.release-stage == 'branch-created' }}
run: |
expectedHash="${{ hashFiles('ci-scripts/templates/org-release-actions.yml') }}"
actualHash="${{ hashFiles('.github/workflows/org-release-actions.yml') }}"
if [[ "$expectedHash" != "$actualHash" ]]; then
echo "::error::Workflow org-release-actions.yml is outdated."
echo "::error::Please replace '.github/workflows/org-release-actions.yml' in this repository with 'templates/org-release-actions.yml' from the ci-scripts repository.'
exit 1
fi
outputs:
release-stage: ${{ steps.context.outputs.release-stage }}
deploy-mode: ${{ steps.context.outputs.deploy-mode }}
project-name: ${{ steps.context.outputs.project-name }}
project-id: ${{ steps.context.outputs.project-id }}
version: ${{ steps.context.outputs.version }}
version-file: ${{ steps.context.outputs.version-file }}
tag: ${{ steps.context.outputs.tag }}
base-branch: ${{ steps.context.outputs.base-branch }}

create-pr:
name: Create PR
runs-on: ubuntu-24.04
needs: [release-context]
if: needs.release-context.outputs.release-stage == 'branch-created'
steps:
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.BALTECH_BOT_ID }}
private-key: ${{ secrets.BALTECH_BOT_KEY }}
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.generate-token.outputs.token }}
- name: Configure git
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@github.com"
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install tox
run: |
python -m pip install --upgrade pip
python -m pip install tox==3.28.0
- name: Restore tox environment from cache
id: tox-cache
uses: actions/cache@v4
with:
path: .tox
key: ${{ runner.os }}-tox-${{ hashFiles('tox.ini') }}-${{ hashFiles('poetry.lock') }}
- name: Prepare next Version
run: |
echo "Increasing version in ${{ needs.release-context.outputs.version-file }} to ${{ needs.release-context.outputs.version }}")
echo "${{ needs.release-context.outputs.version }}" > ${{ needs.release-context.outputs.version-file }}
if not args.project_id:
tox -v -v -- apply-version
else:
tox -v -v -- apply-version --project-name="${{ needs.release-context.outputs.project-name }}"
git add --all
git commit -m"[release] ${{ needs.release-context.outputs.project-name }} ${{ needs.release-context.outputs.version }}"
git push origin ${{ github.ref_name }}
- name: Create PR for release branch
run: |
PR_TITLE="[release] ${{ needs.release-context.outputs.project-name }} ${{ needs.release-context.outputs.version }}"
gh pr create --base ${{ needs.release-context.outputs.base-branch }} --head ${{ github.ref }} --title "$PR_TITLE" --body "" --assignee "${{ github.actor }}"
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Approve PR
run: gh pr review ${{ github.ref_name }} --approve
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Merge PR
run: gh pr merge ${{ github.ref_name }} --rebase --auto
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Cleanup
if: always()
run: rm -rf ci-scripts

create-tag:
name: Create tag
runs-on: ubuntu-24.04
needs: [release-context]
if: ${{ needs.release-context.outputs.release-stage == 'pr-merged' && github.event.pull_request.merged == true }}
steps:
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.BALTECH_BOT_ID }}
private-key: ${{ secrets.BALTECH_BOT_KEY }}
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ steps.generate-token.outputs.token }}
- name: Configure git
run: |
git config user.name "${{ github.event.pusher.name }}"
git config user.email "${{ github.event.pusher.email }}"
- name: Create tag on release commit
run: |
git tag ${{ needs.release-context.outputs.tag }}
git push origin ${{ needs.release-context.outputs.tag }}
Loading

0 comments on commit 39711b0

Please sign in to comment.