Make and Update GitHub Releases #24
This file contains hidden or 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: Make and Update GitHub Releases | |
on: | |
workflow_dispatch: {} | |
release: | |
types: [published] | |
schedule: | |
- cron: '0 0 * * *' # every day at midnight UTC | |
permissions: | |
contents: write | |
jobs: | |
cleanup-github-releases: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
fetch-depth: 0 | |
- name: Install Dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y jq gh | |
- name: Authenticate GitHub CLI | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: gh auth setup-git | |
- name: Delete All Managed Releases and Tags | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
MANAGED_TAGS=("AD-SSO-APIs-Integration" "All-Repository-Files" "BlueTeam-Tools" "Core-ScriptLibrary" "GPOs-Templates" "ITSM-Templates-SVR" "ITSM-Templates-WKS" "READMEs-Files-Package" "SysAdmin-Tools") | |
for tag_prefix in "${MANAGED_TAGS[@]}"; do | |
gh release list --limit 100 --json tagName | jq -r '.[].tagName' | grep "^$tag_prefix" | while read -r tag; do | |
echo "Deleting release and tag: $tag" | |
gh release delete "$tag" -y || true | |
git push origin ":refs/tags/$tag" || true | |
done | |
done | |
update-github-releases: | |
needs: cleanup-github-releases | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
release_name: [ | |
"AD-SSO-APIs-Integration", | |
"All-Repository-Files", | |
"BlueTeam-Tools", | |
"Core-ScriptLibrary", | |
"GPOs-Templates", | |
"ITSM-Templates-SVR", | |
"ITSM-Templates-WKS", | |
"READMEs-Files-Package", | |
"SysAdmin-Tools" | |
] | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
fetch-depth: 0 | |
- name: Install Dependencies | |
run: sudo apt-get install -y zip jq gh | |
- name: Authenticate GitHub CLI | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: gh auth setup-git | |
- name: Set Version Tag | |
id: tag | |
run: echo "VERSION_TAG=${{ matrix.release_name }}-$(date +%Y%m%d)-${GITHUB_SHA::7}" >> $GITHUB_ENV | |
- name: Build and Package Artifacts | |
env: | |
RELEASE_NAME: ${{ matrix.release_name }} | |
run: | | |
mkdir -p artifacts | |
case "$RELEASE_NAME" in | |
BlueTeam-Tools | Core-ScriptLibrary | ITSM-Templates-SVR | ITSM-Templates-WKS | SysAdmin-Tools) | |
cp -r "$RELEASE_NAME" "./temp" | |
cp README.md LICENSE.txt temp/ || true | |
zip -r "artifacts/$RELEASE_NAME.zip" temp | |
rm -rf temp | |
;; | |
GPOs-Templates) | |
mkdir -p temp | |
cp -r SysAdmin-Tools/GroupPolicyObjects-Templates/* temp/ | |
cp SysAdmin-Tools/ActiveDirectory-Management/Export-n-Import-GPOsTool.ps1 temp/ | |
cp README.md LICENSE.txt temp/ || true | |
zip -r "artifacts/$RELEASE_NAME.zip" temp | |
rm -rf temp | |
;; | |
READMEs-Files-Package) | |
mkdir -p temp | |
cp README.md temp/main-README.md || true | |
find . -type f -iname "README.md" ! -path "./README.md" | while read -r file; do | |
repo_dir=$(dirname "$file") | |
repo_name=$(basename "$repo_dir") | |
cp "$file" "temp/${repo_name}-README.md" | |
done | |
zip -r "artifacts/$RELEASE_NAME.zip" temp | |
rm -rf temp | |
;; | |
All-Repository-Files) | |
mkdir -p temp | |
for dir in BlueTeam-Tools Core-ScriptLibrary ITSM-Templates-SVR ITSM-Templates-WKS SysAdmin-Tools; do | |
cp -r "$dir" temp/ | |
done | |
cp README.md LICENSE.txt temp/ || true | |
zip -r "artifacts/$RELEASE_NAME.zip" temp | |
rm -rf temp | |
;; | |
AD-SSO-APIs-Integration) | |
mkdir -p temp | |
cp -r SysAdmin-Tools/ActiveDirectory-SSO-Integrations/* temp/ | |
zip -r "artifacts/$RELEASE_NAME.zip" temp | |
rm -rf temp | |
;; | |
esac | |
- name: Generate SHA256 Checksum | |
run: sha256sum "artifacts/${{ matrix.release_name }}.zip" > "artifacts/${{ matrix.release_name }}.sha256.txt" | |
- name: Extract Changelog for ${{ matrix.release_name }} | |
id: changelog | |
run: | | |
section="## ${{ matrix.release_name }}" | |
body=$(awk -v section="$section" ' | |
$0 == section {found=1; next} | |
/^## / && found {exit} | |
found {print} | |
' CHANGELOG.md) | |
echo "RELEASE_BODY<<EOF" >> $GITHUB_ENV | |
echo "${body:-No changelog available.}" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Create GitHub Release | |
id: create_release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ env.VERSION_TAG }} | |
name: ${{ env.VERSION_TAG }} | |
body: ${{ env.RELEASE_BODY }} | |
draft: false | |
prerelease: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload .zip Artifact | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: artifacts/${{ matrix.release_name }}.zip | |
asset_name: ${{ matrix.release_name }}.zip | |
asset_content_type: application/zip | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload .sha256 Checksum | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: artifacts/${{ matrix.release_name }}.sha256.txt | |
asset_name: ${{ matrix.release_name }}.sha256.txt | |
asset_content_type: text/plain | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload Artifact to Actions | |
uses: actions/upload-artifact@v4 | |
with: | |
name: release-${{ matrix.release_name }} | |
path: artifacts/${{ matrix.release_name }}.zip |