Skip to content

L1

L1 #5

name: Create Production Release
on:
pull_request:
types:
- closed
branches:
- main
permissions:
contents: write
pull-requests: read
jobs:
create_tag:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
outputs:
output1: ${{ steps.previous_tag.outputs.tag_version }}
output2: ${{ steps.tag.outputs.tag_version }}
release_name: ${{ steps.previous_tag.outputs.release_name }}
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
steps:
- name: checkout repo
uses: actions/checkout@v4
with:
repository: ${{github.repository}}.wiki
- name: generate the version number
id: previous_tag
run: |
ls -al
raw_tag=$(grep PRODUCTION Home.textile | cut -d":" -f2- | tr -d '[:space:]')
parsed_tag=$(echo "$raw_tag" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n 1)
if [[ -z "$parsed_tag" ]]; then
parsed_tag="0.0.0"
fi
normalized_tag="v${parsed_tag}"
echo "release_name=Production" >> "$GITHUB_OUTPUT"
echo "$normalized_tag"
echo "tag_version=$normalized_tag" >> "$GITHUB_OUTPUT"
- name: get pull-request-label
id: manual
uses: actions-ecosystem/action-get-merged-pull-request@v1.0.1
with:
github_token: ${{ secrets.github_token }}
- name: debug tag
shell: bash
run: |
echo "${{ steps.previous_tag.outputs.tag_version }}"
- name: create tag name
id: tag
shell: bash
run: |
echo "${{ steps.manual.outputs.labels }}"
version_labels="${{ steps.manual.outputs.labels }}"
base_tag="${{ steps.previous_tag.outputs.tag_version }}"
base_tag="${base_tag#v}"
if [[ ! "$base_tag" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid base tag format: $base_tag"
exit 1
fi
IFS='.' read -r major minor patch <<< "$base_tag"
if [[ "$version_labels" == *"major"* ]]; then
major=$((major + 1))
minor=0
patch=0
elif [[ "$version_labels" == *"minor"* ]]; then
minor=$((minor + 1))
patch=0
else
patch=$((patch + 1))
fi
newTag="v${major}.${minor}.${patch}"
echo "latest-tag=${newTag}" >> "$GITHUB_ENV"
echo "tag_version=${newTag}" >> "$GITHUB_OUTPUT"
echo "New Tag: ${newTag}"
create_release:
if: github.event.pull_request.merged == true
needs: create_tag
runs-on: ubuntu-latest
outputs:
output1: ${{needs.create_tag.outputs.output2}}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create Release
id: create_release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ needs.create_tag.outputs.output2 }}" \
--title "${{ needs.create_tag.outputs.release_name }}-${{ needs.create_tag.outputs.output2 }}" \
--notes "Automated production release"
push-version-wiki:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
needs: create_release
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
steps:
- name: checkout repo
uses: actions/checkout@v4
with:
repository: ${{github.repository}}.wiki
- name: generate the version number
run: |
ls -al
new_version="${{ needs.create_release.outputs.output1 }}"
current_version=$(grep PRODUCTION Home.textile | cut -d":" -f2- | tr -d '[:space:]' || true)
echo "$current_version"
if [[ -z "$current_version" ]]; then
echo "PRODUCTION: $new_version" > Home.textile
else
awk -v version="$new_version" 'BEGIN { updated=0 } {
if (!updated && $0 ~ /PRODUCTION/) {
sub(/:.*/, ": " version)
updated=1
}
print
}' Home.textile > tmp.txt
mv tmp.txt Home.textile
fi
head -n 11 Home.textile > tmp.txt
mv tmp.txt Home.textile
cat Home.textile
- name: Commit files
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "Add changes"
git push