Publish latest to AUR #311
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: Publish to AUR | |
| run-name: Publish latest ${{ inputs.pkgname }} to AUR | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| pkgname: | |
| type: string | |
| required: true | |
| description: "Package name" | |
| jobs: | |
| pkgnames: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| pkgnames: ${{ steps.pkgnames.outputs.pkgnames }} | |
| pkgdata: ${{ steps.pkgnames.outputs.pkgdata }} | |
| steps: | |
| - name: Identify pkgnames | |
| uses: actions/github-script@v7 | |
| id: pkgnames | |
| env: | |
| PKGNAME: ${{ inputs.pkgname }} | |
| COMMITS: ${{ toJSON(github.event.commits) }} | |
| with: | |
| script: | | |
| const isPackageCommit = /^\[([\w\-\d]+)\]/; | |
| const hasSkipCI = /(\[skip-ci\])/; | |
| const commits = JSON.parse(process.env.COMMITS); | |
| if ( commits === null || commits.length == 0) { | |
| if ( process.env.PKGNAME !== null && process.env.PKGNAME.length > 0 ) { | |
| core.setOutput('pkgnames', JSON.stringify([process.env.PKGNAME])); | |
| core.setOutput('pkgdata', JSON.stringify({})); | |
| return; | |
| } | |
| core.setOutput('pkgnames', '[]'); | |
| core.setOutput('pkgdata', JSON.stringify({})); | |
| return; | |
| } | |
| const packages = []; | |
| const pkgdata = {}; | |
| commits.filter(function (commit) { | |
| return isPackageCommit.test(commit.message) && !hasSkipCI.test(commit.message); | |
| }).forEach(function (commit) { | |
| const pkgname = commit.message.match(isPackageCommit)[1]; | |
| packages.push(pkgname); | |
| pkgdata[pkgname] = commit.message; | |
| }); | |
| core.setOutput('pkgnames', JSON.stringify(packages)); | |
| core.setOutput('pkgdata', JSON.stringify(pkgdata)); | |
| publish: | |
| if: needs.pkgnames.outputs.pkgnames != '[]' | |
| needs: pkgnames | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| pkgname: ${{ fromJSON(needs.pkgnames.outputs.pkgnames) }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Clone repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.head_ref }} | |
| ssh-key: ${{ secrets.SSH_KEY_PRIVATE }} | |
| - name: Calculate pkgver and pkgrel | |
| id: pkg | |
| run: | | |
| pkgver=$(awk 'match($0, "^pkgver=([a-zA-Z0-9_.]+)$", arr) {print arr[1]}' ${{ matrix.pkgname }}/PKGBUILD) | |
| pkgrel=$(awk 'match($0, "^pkgrel=([0-9]+)$", arr) {print arr[1]}' ${{ matrix.pkgname }}/PKGBUILD) | |
| echo "new_pkgver=$pkgver" >> $GITHUB_OUTPUT | |
| echo "new_pkgrel=$pkgrel" >> $GITHUB_OUTPUT | |
| - name: Prepare commit message | |
| uses: ./.github/actions/prepare-commit-msg | |
| id: prep | |
| with: | |
| pkgname: ${{ matrix.pkgname }} | |
| new-pkgver: ${{ steps.pkg.outputs.new_pkgver }} | |
| new-pkgrel: ${{ steps.pkg.outputs.new_pkgrel }} | |
| - name: Select commit message | |
| id: commitmsg | |
| env: | |
| PKGDATA: ${{ needs.pkgnames.outputs.pkgdata }} | |
| PKGNAME: ${{ matrix.pkgname }} | |
| PREPARED_MSG: ${{ steps.prep.outputs.commit-msg }} | |
| run: | | |
| ORIGINAL_MSG=$(echo "$PKGDATA" | jq -r --arg pkg "$PKGNAME" '.[$pkg] // ""' | head -1) | |
| if [ -n "$ORIGINAL_MSG" ]; then | |
| { | |
| echo "commit-msg<<EOF" | |
| echo "$ORIGINAL_MSG" | |
| echo "EOF" | |
| } >> $GITHUB_OUTPUT | |
| else | |
| { | |
| echo "commit-msg<<EOF" | |
| echo "$PREPARED_MSG" | |
| echo "EOF" | |
| } >> $GITHUB_OUTPUT | |
| fi | |
| - name: Publish to AUR | |
| uses: ./.github/actions/publish-to-aur | |
| with: | |
| pkgname: ${{ matrix.pkgname }} | |
| commit-msg: ${{ steps.commitmsg.outputs.commit-msg }} | |
| new-pkgver: ${{ steps.pkg.outputs.new_pkgver }} | |
| new-pkgrel: ${{ steps.pkg.outputs.new_pkgrel }} | |
| commit-email: ${{ secrets.GIT_EMAIL }} | |
| commit-user: ${{ secrets.GIT_USER }} | |
| ssh-priv-key: ${{ secrets.SSH_KEY_PRIVATE }} |