1- # Publish workflow to add a new version of a package
1+ # GitHub Actions workflow for publishing DaxLib packages
22#
3- # This workflow creates a branch in the daxlib/daxlib GitHub repository
4- # to add a new version of the package. After the workflow completes,
5- # a pull request should be created manually to merge the changes.
6- #
7- # TODO:
8- # - Automate the PR creation
3+ # This workflow automates the publication of a new package version to the daxlib/daxlib repository.
4+ # Maintainers can trigger it manually via the "Run workflow" button in the Actions tab.
5+ #
6+ # Steps:
7+ # - Extracts the package name and version from the manifest file
8+ # - Creates or updates a release branch in the upstream repository
9+ # - Copies the package files to the appropriate folder structure
10+ # - Commits and pushes the changes
11+ # - Creates a pull request for new releases
912
1013name : publish-package-pr
1114
1518permissions :
1619 contents : read
1720
18- env :
19- DAXLIB_NAME : ' DaxLib.Convert'
20- DAXLIB_PATH : ' packages/d/daxlib.convert'
21-
2221jobs :
2322 publish :
2423 runs-on : ubuntu-latest
2524 steps :
2625 # Checkout the current repository
27- - name : checkout source
26+ - name : Checkout source
2827 uses : actions/checkout@v4
2928 with :
3029 repository : ${{ github.repository }}
3130 path : source-repo
3231
3332 # Checkout the upstream repository daxlib/daxlib
34- - name : checkout upstream
33+ - name : Checkout upstream
3534 uses : actions/checkout@v4
3635 with :
3736 repository : daxlib/daxlib
3837 path : upstream-repo
3938 token : ${{ secrets.DAXLIB_TOKEN }} # Required to push changes
40-
39+
4140 # Configure Git
42- - name : git config
41+ - name : Git config
4342 working-directory : upstream-repo
4443 run : |
4544 git config user.name "${{ github.actor }}"
4645 git config user.email "${{ github.actor }}@users.noreply.github.com"
4746
48- # Extract package version from manifest
49- - name : get package version
50- id : get_package_version
47+ # Read the package version from the manifest
48+ - name : Read package manifest
49+ id : package
5150 working-directory : source-repo
5251 run : |
53- VERSION=$(jq -r '.version' src/manifest.daxlib)
54- echo "version=$VERSION" >> $GITHUB_OUTPUT
55- echo "Package version: $VERSION"
52+ PACKAGE_NAME=$(jq -r '.id' src/manifest.daxlib)
53+ echo "name=${PACKAGE_NAME}" >> $GITHUB_OUTPUT
54+ echo "Package name: ${PACKAGE_NAME}"
55+ PACKAGE_VERSION=$(jq -r '.version' src/manifest.daxlib)
56+ echo "version=${PACKAGE_VERSION}" >> $GITHUB_OUTPUT
57+ echo "Package version: ${PACKAGE_VERSION}"
58+ PACKAGE_FOLDER="packages/$(echo "${PACKAGE_NAME}" | cut -c1 | tr '[:upper:]' '[:lower:]')/$(echo "${PACKAGE_NAME}" | tr '[:upper:]' '[:lower:]')/${PACKAGE_VERSION}"
59+ echo "folder=${PACKAGE_FOLDER}" >> $GITHUB_OUTPUT
60+ echo "Package folder: ${PACKAGE_FOLDER}"
5661
57- # Create the feature branch for the new version
58- - name : create release branch
62+ # Checkout the branch (or create it if it doesn't exist)
63+ - name : Checkout branch
64+ id : branch
5965 working-directory : upstream-repo
60- run : git checkout -b "${{ github.event.repository.name }}/release-${{ env.DAXLIB_NAME }}-${{ steps.get_package_version.outputs.version }}"
66+ run : |
67+ BRANCH_NAME="${{ github.event.repository.name }}/publish-${{ steps.package.outputs.name }}-${{ steps.package.outputs.version }}"
68+ echo "name=${BRANCH_NAME}" >> $GITHUB_OUTPUT
69+ echo "Branch name: ${BRANCH_NAME}"
70+ git fetch origin
71+ if git show-ref --verify --quiet "refs/remotes/origin/${BRANCH_NAME}"; then
72+ echo "action=Update" >> $GITHUB_OUTPUT
73+ git checkout "${BRANCH_NAME}"
74+ else
75+ echo "action=Add" >> $GITHUB_OUTPUT
76+ git checkout -b "${BRANCH_NAME}"
77+ fi
6178
62- # Create the package folder for the new version
63- - name : create package folder
79+ # Create the package folder if it doesn't exist
80+ - name : Create package folder
6481 working-directory : upstream-repo
65- run : mkdir -p "${{ env.DAXLIB_PATH }}/${{ steps.get_package_version .outputs.version }}"
82+ run : mkdir -p "${{ steps.package .outputs.folder }}"
6683
6784 # Copy package files to the new folder
68- - name : copy package files
69- run : cp -rv source-repo/src/* "upstream-repo/${{ env.DAXLIB_PATH }}/${{ steps.get_package_version .outputs.version }}/"
85+ - name : Copy package files
86+ run : cp -rv source-repo/src/* "upstream-repo/${{ steps.package .outputs.folder }}/"
7087
71- # Stage and commit changes
72- - name : git commit changes
88+ # Commit changes
89+ - name : Git commit changes
7390 working-directory : upstream-repo
74- run : git add -A && git commit -m "Add package ${{ env.DAXLIB_NAME }} version ${{ steps.get_package_version .outputs.version }}"
91+ run : git add -A && git commit -m "${{ steps.branch.outputs.action }} package ${{ steps.package.outputs.name }} version ${{ steps.package .outputs.version }}"
7592
76- # Push branch to upstream repository
77- - name : git push upstream
93+ # Push to upstream
94+ - name : Git push upstream
7895 working-directory : upstream-repo
79- run : git push origin "${{ github.event.repository.name }}/release-${{ env.DAXLIB_NAME }}-${{ steps.get_package_version .outputs.version }}"
96+ run : git push origin "${{ steps.branch .outputs.name }}"
8097
98+ # Create the pull request (if the branch was created)
99+ - name : Create pull request
100+ if : steps.branch.outputs.action == 'Add'
101+ working-directory : upstream-repo
102+ env :
103+ GH_TOKEN : ${{ secrets.DAXLIB_TOKEN }}
104+ run : |
105+ gh pr create \
106+ --title "Add package \`${{ steps.package.outputs.name }}\` version ${{ steps.package.outputs.version }}" \
107+ --body "Automated package publication from ${{ github.repository }}" \
108+ --base main \
109+ --head "${{ steps.branch.outputs.name }}"
0 commit comments