|
| 1 | +# GitHub Actions workflow to publish DaxLib packages |
| 2 | +# |
| 3 | +# Version: 1.0.0 |
| 4 | +# |
| 5 | +# HOW TO USE: |
| 6 | +# 1. Go to "Actions" in your GitHub repository |
| 7 | +# 2. Click on "publish-package" in the workflow list |
| 8 | +# 3. Click the "Run workflow" button and confirm |
| 9 | +# 4. Wait for the workflow to complete |
| 10 | +# 5. Create a Pull Request to the official DaxLib repository (link provided in the summary after completion) |
| 11 | +# |
| 12 | +# WHAT IT DOES: |
| 13 | +# - Reads your package from the current repository |
| 14 | +# - Copies it to your daxlib fork |
| 15 | +# - Creates (or updates) a branch with your changes |
| 16 | +# - Provides you with a link to open a Pull Request to the official DaxLib repository |
| 17 | +# |
| 18 | +# REQUIREMENTS: |
| 19 | +# - A fork of the daxlib repository under your account |
| 20 | +# - A Personal Access Token (PAT) saved as DAXLIBFORK_PAT in repository secrets |
| 21 | + |
| 22 | +name: publish-package |
| 23 | + |
| 24 | +on: |
| 25 | + workflow_dispatch: |
| 26 | + |
| 27 | +permissions: |
| 28 | + contents: read |
| 29 | + |
| 30 | +env: |
| 31 | + # Name of the forked daxlib repository (change if your fork has a different name) |
| 32 | + DAXLIBFORK_NAME: ${{ github.repository_owner }}/daxlib |
| 33 | + |
| 34 | +jobs: |
| 35 | + publish: |
| 36 | + runs-on: ubuntu-latest |
| 37 | + steps: |
| 38 | + # Checkout the current repository |
| 39 | + - name: Checkout source |
| 40 | + uses: actions/checkout@v4 |
| 41 | + with: |
| 42 | + repository: ${{ github.repository }} |
| 43 | + path: source-repo |
| 44 | + |
| 45 | + # Checkout the daxlib fork repository |
| 46 | + - name: Checkout upstream |
| 47 | + uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + repository: ${{ env.DAXLIBFORK_NAME }} |
| 50 | + path: fork-repo |
| 51 | + token: ${{ secrets.DAXLIBFORK_PAT }} |
| 52 | + |
| 53 | + # Configure Git |
| 54 | + - name: Git config |
| 55 | + working-directory: fork-repo |
| 56 | + run: | |
| 57 | + git config user.name "${{ github.actor }}" |
| 58 | + git config user.email "${{ github.actor }}@users.noreply.github.com" |
| 59 | +
|
| 60 | + # Read the package version from the manifest |
| 61 | + - name: Read package manifest |
| 62 | + id: package |
| 63 | + working-directory: source-repo |
| 64 | + run: | |
| 65 | + PACKAGE_NAME=$(jq -r '.id' src/manifest.daxlib) |
| 66 | + echo "name=${PACKAGE_NAME}" >> $GITHUB_OUTPUT |
| 67 | + echo "Package name: ${PACKAGE_NAME}" |
| 68 | + PACKAGE_VERSION=$(jq -r '.version' src/manifest.daxlib) |
| 69 | + echo "version=${PACKAGE_VERSION}" >> $GITHUB_OUTPUT |
| 70 | + echo "Package version: ${PACKAGE_VERSION}" |
| 71 | + PACKAGE_FOLDER="packages/$(echo "${PACKAGE_NAME}" | cut -c1 | tr '[:upper:]' '[:lower:]')/$(echo "${PACKAGE_NAME}" | tr '[:upper:]' '[:lower:]')/${PACKAGE_VERSION}" |
| 72 | + echo "folder=${PACKAGE_FOLDER}" >> $GITHUB_OUTPUT |
| 73 | + echo "Package folder: ${PACKAGE_FOLDER}" |
| 74 | +
|
| 75 | + # Checkout the branch (or create it if it doesn't exist) |
| 76 | + - name: Checkout branch |
| 77 | + id: branch |
| 78 | + working-directory: fork-repo |
| 79 | + run: | |
| 80 | + BRANCH_NAME="${{ github.event.repository.name }}/publish-${{ steps.package.outputs.name }}-${{ steps.package.outputs.version }}" |
| 81 | + echo "name=${BRANCH_NAME}" >> $GITHUB_OUTPUT |
| 82 | + echo "Branch name: ${BRANCH_NAME}" |
| 83 | + git fetch origin |
| 84 | + if git show-ref --verify --quiet "refs/remotes/origin/${BRANCH_NAME}"; then |
| 85 | + echo "action=Update" >> $GITHUB_OUTPUT |
| 86 | + git checkout "${BRANCH_NAME}" |
| 87 | + else |
| 88 | + echo "action=Add" >> $GITHUB_OUTPUT |
| 89 | + git checkout -b "${BRANCH_NAME}" |
| 90 | + fi |
| 91 | + |
| 92 | + # Create the package folder if it doesn't exist |
| 93 | + - name: Create package folder |
| 94 | + working-directory: fork-repo |
| 95 | + run: mkdir -p "${{ steps.package.outputs.folder }}" |
| 96 | + |
| 97 | + # Copy package files to the new folder |
| 98 | + - name: Copy package files |
| 99 | + run: cp -rv source-repo/src/* "fork-repo/${{ steps.package.outputs.folder }}/" |
| 100 | + |
| 101 | + # Commit changes. If there are no changes, this will fail and stop the workflow |
| 102 | + - name: Git commit changes |
| 103 | + working-directory: fork-repo |
| 104 | + run: git add -A && git commit -m "${{ steps.branch.outputs.action }} package \`${{ steps.package.outputs.name }}\` version ${{ steps.package.outputs.version }}" |
| 105 | + |
| 106 | + # Push to upstream |
| 107 | + - name: Git push branch |
| 108 | + working-directory: fork-repo |
| 109 | + run: git push origin "${{ steps.branch.outputs.name }}" |
| 110 | + |
| 111 | + # Print summary |
| 112 | + - name: Print summary |
| 113 | + run: | |
| 114 | + if [ "${{ steps.branch.outputs.action }}" == "Add" ]; then |
| 115 | + STATUS_ICON="✅" |
| 116 | + BADGE_COLOR="blue" |
| 117 | + STAT_INSTRUCTIONS="Your package is ready to be published." |
| 118 | + NEXT_INSTRUCTIONS="Click the button below to create a Pull Request and submit your package to DAX Lib:" |
| 119 | + else |
| 120 | + STATUS_ICON="🔄" |
| 121 | + BADGE_COLOR="orange" |
| 122 | + STAT_INSTRUCTIONS="Your changes have been applied and are ready for review." |
| 123 | + NEXT_INSTRUCTIONS="If a Pull Request already exists, it has already been updated automatically. Otherwise, click the button below to create one." |
| 124 | + fi |
| 125 | + |
| 126 | + cat >> $GITHUB_STEP_SUMMARY << EOF |
| 127 | + ## ${STATUS_ICON} Package **\`${{ steps.package.outputs.name }}\`** version **\`${{ steps.package.outputs.version }}\`** |
| 128 | + |
| 129 | + ${STAT_INSTRUCTIONS} |
| 130 | +
|
| 131 | + ## 📝 Next Step |
| 132 | + |
| 133 | + ${NEXT_INSTRUCTIONS} |
| 134 | + |
| 135 | + [](https://github.com/${{ env.DAXLIBFORK_NAME }}/pull/new/${{ steps.branch.outputs.name }}) |
| 136 | + |
| 137 | + <details> |
| 138 | + <summary>📋 Details (click to expand)</summary> |
| 139 | + |
| 140 | + | | | |
| 141 | + |---|---| |
| 142 | + | Package name | \`${{ steps.package.outputs.name }}\` | |
| 143 | + | Package version | \`${{ steps.package.outputs.version }}\` | |
| 144 | + | Package folder | \`${{ steps.package.outputs.folder }}\` | |
| 145 | + | Source | \`${{ github.repository }}\` @ \`${{ github.ref_name }}\` | |
| 146 | + | Fork | \`${{ env.DAXLIBFORK_NAME }}\` @ \`${{ steps.branch.outputs.name }}\` | |
| 147 | + | Create Pull Request URL | \`https://github.com/${{ env.DAXLIBFORK_NAME }}/pull/new/${{ steps.branch.outputs.name }}\` | |
| 148 | + |
| 149 | + </details> |
| 150 | + EOF |
0 commit comments