Update Packagist #9
This file contains 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: Update Packagist | |
on: | |
workflow_dispatch: | |
inputs: | |
selected_tag: | |
description: 'Tag to use' | |
required: false | |
push: | |
tags: | |
- '*' # This matches all tag pushes | |
jobs: | |
fetch-tags: | |
if: github.event_name == 'workflow_dispatch' # Only run when triggered manually | |
runs-on: ubuntu-latest | |
outputs: | |
tags: ${{ steps.get-tags.outputs.tag-list }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Get Tags | |
id: get-tags | |
run: | | |
tags=$(git tag --sort=-v:refname | head -n 10) # Fetch the 10 most recent tags | |
echo "Fetched tags:" | |
echo "$tags" | |
# Use environment file for setting outputs | |
echo "tag-list=$tags" >> $GITHUB_OUTPUT | |
- name: Print Tags for User | |
run: | | |
echo "Here are the latest tags:" | |
echo "${{ steps.get-tags.outputs.tag-list }}" | |
update-packagist: | |
runs-on: ubuntu-latest | |
needs: fetch-tags | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Determine Tag to Use | |
id: determine-tag | |
run: | | |
if [ "${{ github.event_name }}" == "push" ]; then | |
TAG_NAME="${GITHUB_REF##*/}" | |
echo "Pushed tag: $TAG_NAME" | |
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT | |
else | |
echo "Manually selected tag: ${{ github.event.inputs.selected_tag }}" | |
echo "tag=${{ github.event.inputs.selected_tag }}" >> $GITHUB_OUTPUT | |
fi | |
- name: Trigger Packagist update | |
run: | | |
echo "Updating Packagist for tag ${{ steps.determine-tag.outputs.tag }}" | |
curl -X POST "https://packagist.org/api/update-package?username=${{ env.PACKAGIST_USERNAME }}&apiToken=${{ secrets.PACKAGIST_API_TOKEN }}" \ | |
-d '{"repository": "https://github.com/${{ github.repository }}"}' \ | |
-H "Content-Type: application/json" | |
env: | |
PACKAGIST_API_TOKEN: ${{ secrets.PACKAGIST_API_TOKEN }} |