template #20
Workflow file for this run
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: template | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| BRANCH: | |
| description: 'Branch to run the workflow on' | |
| required: true | |
| default: 'live' | |
| type: string | |
| TARGET_BRANCH_SUFFIX: | |
| description: 'Suffix for the target branch of this repo' | |
| required: false | |
| default: '' | |
| type: string | |
| FLAVOR: | |
| description: 'Flavor to filter the input for' | |
| required: true | |
| default: 'mainline' | |
| type: choice | |
| options: | |
| - mainline | |
| - mists | |
| - cata | |
| - wrath | |
| - tbc | |
| - vanilla | |
| FORCE_UPDATE: | |
| description: 'Force update the branch' | |
| required: false | |
| default: false | |
| type: boolean | |
| MIX_ANNOTATIONS_INTO_SOURCE: | |
| description: 'Include all lua source files, and add class annotations to the source files' | |
| required: false | |
| default: false | |
| type: boolean | |
| INCLUDE_RAW_XML_SOURCE: | |
| description: 'Include raw XML source files' | |
| required: false | |
| default: false | |
| type: boolean | |
| workflow_call: | |
| inputs: | |
| BRANCH: | |
| description: 'Branch to run the workflow on' | |
| required: true | |
| default: 'live' | |
| type: string | |
| TARGET_BRANCH_SUFFIX: | |
| description: 'Suffix for the target branch of this repo' | |
| required: false | |
| default: '' | |
| type: string | |
| FLAVOR: | |
| description: 'Flavor to filter the input for' | |
| required: true | |
| default: 'mainline' | |
| type: string | |
| FORCE_UPDATE: | |
| description: 'Force update the branch' | |
| required: false | |
| default: false | |
| type: boolean | |
| MIX_ANNOTATIONS_INTO_SOURCE: | |
| description: 'Include all lua source files, and add class annotations to the source files' | |
| required: false | |
| default: false | |
| type: boolean | |
| INCLUDE_RAW_XML_SOURCE: | |
| description: 'Include raw XML source files' | |
| required: false | |
| default: false | |
| type: boolean | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Checkout latest Getho/wow-ui-source | |
| if: ${{ steps.check.outputs.skip != 'true' }} | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: gethe/wow-ui-source | |
| path: ./.wow-ui-source | |
| fetch-depth: 1 | |
| ref: ${{ inputs.BRANCH }} | |
| - name: Checkout or create latest Annotations branch | |
| if: ${{ steps.check.outputs.skip != 'true' }} | |
| run: | | |
| set -ex | |
| git clone "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY" ./.annotations_temp | |
| cd ./.annotations_temp | |
| git fetch --prune origin | |
| target_branch_name="${{ inputs.BRANCH }}${{ inputs.TARGET_BRANCH_SUFFIX }}" | |
| git config user.name "GitHub Actions" | |
| git config user.email [email protected] | |
| cleanup() { | |
| find . -maxdepth 1 -mindepth 1 ! -name .git -exec rm -rf {} + | |
| } | |
| if git show-ref --quiet "refs/remotes/origin/${target_branch_name}"; then | |
| echo "Re-using existing branch..." | |
| git fetch origin "${target_branch_name}" | |
| git checkout -b "${target_branch_name}" "origin/${target_branch_name}" | |
| git pull --rebase origin "${target_branch_name}" | |
| git rm -rfq . || true | |
| cleanup | |
| else | |
| echo "Creating new branch..." | |
| cleanup | |
| git rm -rfq . || true | |
| git checkout --orphan "${target_branch_name}" | |
| git commit --allow-empty --message "Initialize" | |
| git push --set-upstream origin "${target_branch_name}" | |
| fi | |
| cp ../annotation_branch_readme.md README.md | |
| - name: Compare local and remote commit hashes | |
| id: check | |
| run: | | |
| set -ex | |
| if [[ "${{ inputs.FORCE_UPDATE }}" == "true" ]]; then | |
| echo "skip=false" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| target_branch_name="${{ inputs.BRANCH }}${{ inputs.TARGET_BRANCH_SUFFIX }}" | |
| cd ./.wow-ui-source | |
| remote_commit_hash=$(git rev-parse HEAD) | |
| cd ../.annotations_temp | |
| local_commit_hash=$(git log --oneline -n1 | grep -Po "Synced to commit \K.*" || echo "unknown") | |
| echo "${target_branch_name}: ${local_commit_hash} -> ${remote_commit_hash}" | |
| if [[ "${local_commit_hash}" == "${remote_commit_hash}" ]]; then | |
| echo "Branch is already up-to-date." | |
| echo "skip=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Setup PHP with composer v2 | |
| if: ${{ steps.check.outputs.skip != 'true' }} | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.3' | |
| extensions: xml, dom | |
| tools: composer:v2 | |
| - name: Install dependencies | |
| if: ${{ steps.check.outputs.skip != 'true' }} | |
| run: | | |
| set -ex | |
| composer install --no-interaction --no-progress --no-suggest --prefer-dist | |
| - name: Create annotations and push | |
| if: ${{ steps.check.outputs.skip != 'true' }} | |
| run: | | |
| set -ex | |
| branch_name="${{ inputs.BRANCH }}" | |
| target_branch_name="${{ inputs.BRANCH }}${{ inputs.TARGET_BRANCH_SUFFIX }}" | |
| flavor=${{ inputs.FLAVOR }} | |
| cd ./.wow-ui-source | |
| remote_commit_hash=$(git rev-parse HEAD) | |
| message="Synced to commit ${remote_commit_hash}" | |
| cd .. | |
| extraArgs="" | |
| if [[ "${{ inputs.MIX_ANNOTATIONS_INTO_SOURCE }}" == "true" ]]; then | |
| extraArgs="${extraArgs} --mixAnnotationsIntoSource" | |
| fi | |
| if [[ "${{ inputs.INCLUDE_RAW_XML_SOURCE }}" == "true" ]]; then | |
| extraArgs="${extraArgs} --includeRawXmlSource" | |
| fi | |
| bin/annotate ${flavor} --inputDir=./.wow-ui-source/Interface --outputDir=./.annotations_temp/Annotations --linkPrefix="https://github.com/Gethe/wow-ui-source/blob/${branch_name}/Interface" ${extraArgs} | |
| cd ./.annotations_temp | |
| git config user.name "GitHub Actions" | |
| git config user.email [email protected] | |
| git add -v . | |
| echo "Checking if there are changes to be commited and pushed..." | |
| if [[ -n $(git status --porcelain) ]] || ! git diff --quiet; then | |
| if git commit --message "${message}" >/dev/null 2>&1; then | |
| echo "Commiting and pushing..." | |
| git push --force-with-lease --set-upstream origin "${target_branch_name}" | |
| else | |
| echo "Unable to commit." | |
| fi | |
| else | |
| echo "Nothing to commit." | |
| fi | |
| echo "Done!" |