Skip to content

Commit

Permalink
actions: enable actions
Browse files Browse the repository at this point in the history
  • Loading branch information
wookiefriseur committed Jun 12, 2023
1 parent b967f31 commit 51b984e
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 72 deletions.
25 changes: 25 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

# Yaml files
[*.{yml,yaml}]
indent_size = 2

# Markdown files
[*.md]
indent_size = 2

# Markdown files
[*.md]
indent_size = 2

# PowerShell files
[*.{ps1,psm1,psd1}]
indent_size = 2
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.github/CODEOWNERS @wookiefriseur
/.github/workflows/* @wookiefriseur
135 changes: 135 additions & 0 deletions .github/workflows/create_release_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: CreateReleasePR

# Connected workflows are:
# 1. RunTests - run_tests.yml
# 2. 📍CreateReleasePR - create_release_pr.yml
# 3. Release - release.yml
# 4. ProxyUpdateSubmoduleRefs - valor-moduls/proxy_update_submodule_refs.yml

# fixes version labels
# updates the version in the module manifest
# creates a release PR with the new version number
# triggers RunTests to run

permissions:
contents: write
pull-requests: write
on:
# When triggered manually: Gets data from most recently merged PR
workflow_dispatch:
# When triggered by merge: Gets data from the PR that triggered the event
pull_request:
branches: [main]
types: [closed]

jobs:
update_and_pr:
# run if the merged PR was not already processed by MergeAndRelease workflow (release branches)
# run if the merged PR is marked as a release ('actions:RELEASE')
# run if the workflow was started manually
if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged && !startsWith(github.event.pull_request.head.ref, 'release/') && (contains(github.event.pull_request.labels.*.name, 'actions:RELEASE')))

runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: main
- run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Get PR details
id: get_pr_details
run: |
if('${{ github.event_name }}' -ne 'workflow_dispatch') {
$labels = "${{ join(github.event.pull_request.labels.*.name, ', ') }}"
$pr_number = "${{ github.event.pull_request.number }}"
} else {
$latestPRs = gh pr list --base main --state merged --json number,labels,mergedAt --limit 10 | ConvertFrom-JSON
$VERSION_LABELS = @('version:MAJOR', 'version:MINOR', 'version:PATCH')
$latestReleasePR = $latestPRs | Where-Object {
$VERSION_LABELS.Contains($_.labels.name)
} | Sort-Object -Property mergedAt -Descending | Select-Object -First 1
$labels = $latestReleasePR.labels.name -join ', '
$pr_number = $latestReleasePR.number
}
Write-Output "LABELS=$labels" >> $env:GITHUB_OUTPUT
Write-Output "PR_NUMBER=$pr_number" >> $env:GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Fix version labels and get Version Impact
id: get_versionchange
run: |
# Labels can come in like: "version:MAJOR, version:MINOR, somelabel"
switch ('${{ steps.get_pr_details.outputs.LABELS }}')
{
{ $_ -match "version:MAJOR" } {
Write-Output "🏷️ label MAJOR detected"
gh pr edit ${{ github.event.pull_request.number }} --remove-label "version:MINOR" --remove-label "version:PATCH"
$impact = "major"
break
}
{ $_ -match "version:MINOR" } {
Write-Output "🏷️ label MINOR detected"
gh pr edit ${{ github.event.pull_request.number }} --remove-label "version:PATCH"
$impact = "minor"
break
}
{ $_ -match "version:PATCH" } {
Write-Output "🏷️ label PATCH detected"
$impact = "patch"
break
}
default {
Write-Output "🏷️ No version label detected, setting default"
gh pr edit ${{ github.event.pull_request.number }} --add-label "version:MINOR"
$impact = "minor"
}
}
Write-Output "IMPACT=$impact" >> $env:GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Creates temporary release branch, will be deleted in another workflow
- name: Create Release Branch
id: release_branch
run: |
$BRANCH = "release/pr-${{ steps.get_pr_details.outputs.PR_NUMBER }}"
git branch -d "$BRANCH" || true
git push origin --delete "$BRANCH" || true
git branch "$BRANCH"
git checkout "$BRANCH"
git push --set-upstream origin "$BRANCH"
Write-Host "BRANCH_NAME=$BRANCH" >> $env:GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Update Version
id: update_version
run: |
# Load Update-PSManifestVersion <MANIFEST_FILE> <IMPACT> | returns new version
Invoke-Expression (Invoke-RestMethod -Uri https://raw.githubusercontent.com/wookiefriseur/valor-modulis/main/.scripts/updatePSManifest.ps1)
$manifestFile = $(Get-ChildItem *.psd1 -Recurse | Select-Object -First 1).FullName
$newVersion = Update-PSManifestVersion $manifestFile ${{ steps.get_versionchange.outputs.IMPACT }}
Write-Output "VERSION=$newVersion" >> $env:GITHUB_OUTPUT
- name: Update files
id: update_files
run: |
git add .
git commit -m "update to ${{ steps.update_version.outputs.VERSION }}"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Release PR
run: |
gh pr create `
--title "Release ${{ steps.update_version.outputs.VERSION }}" `
--base main `
--fill
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57 changes: 57 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Release

# Connected workflows are:
# 1. RunTests - run_tests.yml
# 2. CreateReleasePR - create_release_pr.yml
# 3. 📍Release - release.yml
# 4. ProxyUpdateSubmoduleRefs - valor-moduls/proxy_update_submodule_refs.yml

# Creates a release from main

permissions:
contents: write
pull-requests: write
on:
workflow_dispatch:
pull_request:
branches: [main]
types: [closed]

jobs:
merge_and_release:
# Run when triggered manually
# Run when merged from "release/"
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'release/'))

runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: main
- run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Get Version
id: get_version
run: |
VERSION=$(grep --only-matching --perl-regexp "ModuleVersion\s*=\s*'\K[0-9\.]+" *.psd1)
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Create Release
run: |
gh release create "${{ steps.get_version.outputs.VERSION }}" \
--target main \
--generate-notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Tell the main repo that there is a new version in town
# The main repo will update the reference, if the latest release changed
- name: Trigger update in main repo
run: |
gh workflow run proxy_update_submodule_refs.yml \
--repo wookiefriseur/valor-modulis
env:
GITHUB_TOKEN: ${{ secrets.VM_ACTIONS }}
53 changes: 53 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: RunTests

# Connected workflows are:
# 1. 📍RunTests - run_tests.yml
# 2. CreateReleasePR - create_release_pr.yml
# 3. Release - release.yml
# 4. ProxyUpdateSubmoduleRefs - valor-moduls/proxy_update_submodule_refs.yml

# checks code of a PR as a precondition for merges

on:
# Test PRs generated by actions
workflow_dispatch:
inputs:
ref:
description: Branch (release/pr-123) or commit hash (40 chars) to test
required: true
type: string
# Test PRs and commits to PRs from users
pull_request_target:
branches: [main]
types: [opened, synchronize]

jobs:
run_tests:
runs-on: windows-latest

steps:
- name: Get PR sha
id: get_ref
run: |
if('${{ github.event_name }}' -eq 'workflow_dispatch') {
$REFERENCE = '${{ github.event.inputs.ref }}'
} else {
$REFERENCE = '${{ github.event.pull_request.head.ref }}'
}
Write-Output "REFERENCE=$REFERENCE" >> $env:GITHUB_OUTPUT
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ steps.get_ref.outputs.REFERENCE }}
- run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Run Tests
shell: pwsh
id: testresults
run: |
Set-PSRepository psgallery -InstallationPolicy trusted
Install-Module -Name Pester -Confirm:$false -Force
Invoke-Pester
72 changes: 0 additions & 72 deletions .github/workflows/update_submodule.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode
.idea
6 changes: 6 additions & 0 deletions .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
overrides:
- files: "*.yml"
options:
editorconfig: true
singleQuote: false
printWidth: 80

0 comments on commit 51b984e

Please sign in to comment.