|
1 | 1 | name: Update version.json and create PR
|
2 | 2 |
|
| 3 | +# Trigger the github action when a new release is published |
3 | 4 | on:
|
4 | 5 | release:
|
5 | 6 | types: [published]
|
|
9 | 10 | runs-on: ubuntu-latest
|
10 | 11 |
|
11 | 12 | steps:
|
| 13 | + |
| 14 | + # Step 1: Checkout repository |
12 | 15 | - name: Checkout repository
|
13 | 16 | uses: actions/checkout@v3
|
14 | 17 |
|
| 18 | + # Step 2: Get latest release version information |
15 | 19 | - name: Get release information
|
16 | 20 | id: get_release
|
17 | 21 | run: |
|
18 | 22 | response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/latest)
|
19 | 23 | echo "$response" | jq '.tag_name, .name, .published_at, .body, .html_url' | tee /tmp/release_info
|
20 |
| - echo "::set-output name=tag_name::$(echo "$response" | jq -r .tag_name)" |
21 |
| - echo "::set-output name=name::$(echo "$response" | jq -r .name)" |
22 |
| - echo "::set-output name=published_at::$(echo "$response" | jq -r .published_at)" |
23 |
| - echo "::set-output name=body::$(echo "$response" | jq -r .body)" |
24 |
| - echo "::set-output name=html_url::$(echo "$response" | jq -r .html_url)" |
25 |
| -
|
| 24 | + echo "tag_name=$(echo "$response" | jq -r .tag_name)" >> $GITHUB_ENV |
| 25 | + echo "name=$(echo "$response" | jq -r .name)" >> $GITHUB_ENV |
| 26 | + echo "published_at=$(echo "$response" | jq -r .published_at)" >> $GITHUB_ENV |
| 27 | + echo "body=$(echo "$response" | jq -r .body)" >> $GITHUB_ENV |
| 28 | + echo "html_url=$(echo "$response" | jq -r .html_url)" >> $GITHUB_ENV |
26 | 29 |
|
| 30 | + # Step 3: Update version.json file with latest information |
27 | 31 | - name: Update version.json
|
28 | 32 | run: |
|
29 | 33 | echo '{
|
30 |
| - "tag_name": "${{ steps.get_release.outputs.tag_name }}", |
31 |
| - "release_name": "${{ steps.get_release.outputs.name }}", |
32 |
| - "published_at": "${{ steps.get_release.outputs.published_at }}", |
33 |
| - "body": "${{ steps.get_release.outputs.body }}" |
34 |
| - "html_url": "${{ steps.get_release.outputs.html_url }}" |
| 34 | + "tag_name": "${{ env.tag_name }}", |
| 35 | + "release_name": "${{ env.name }}", |
| 36 | + "published_at": "${{ env.published_at }}", |
| 37 | + "body": "${{ env.body }}", |
| 38 | + "html_url": "${{ env.html_url }}" |
35 | 39 | }' > version.json
|
36 | 40 |
|
| 41 | + # Step 4: Configure a user to create a branch and then push changes |
| 42 | + - name: Configure Git user |
| 43 | + run: | |
| 44 | + git config --global user.name "GitHub Actions" |
| 45 | + git config --global user.email "[email protected]" |
| 46 | +
|
| 47 | + # Step 5: Create a new branch for version updates |
37 | 48 | - name: Create new branch
|
38 | 49 | run: |
|
39 |
| - git checkout -b update-version-${{ steps.get_release.outputs.tag_name }} |
| 50 | + git checkout -b update-version-${{ env.tag_name }} |
40 | 51 | git add version.json
|
41 |
| - git commit -m "Update version.json for release ${{ steps.get_release.outputs.tag_name }}" |
| 52 | + git commit -m "Update version.json for release ${{ env.tag_name }}" |
42 | 53 |
|
| 54 | + # Step 6: Push branch |
43 | 55 | - name: Push branch
|
44 | 56 | run: |
|
45 |
| - git push origin update-version-${{ steps.get_release.outputs.tag_name }} |
| 57 | + git push origin update-version-${{ env.tag_name }} |
46 | 58 | env:
|
47 | 59 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
48 | 60 |
|
| 61 | + # Step 7: Create a pull request from the pushed branch |
49 | 62 | - name: Create Pull Request
|
50 | 63 | run: |
|
51 | 64 | curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" \
|
52 | 65 | https://api.github.com/repos/${{ github.repository }}/pulls \
|
53 | 66 | -d '{
|
54 |
| - "title": "Update version.json for release ${{ steps.get_release.outputs.tag_name }}", |
| 67 | + "title": "Update version.json for release ${{ env.tag_name }}", |
55 | 68 | "body": "This PR updates version.json with the latest release information.",
|
56 |
| - "head": "update-version-${{ steps.get_release.outputs.tag_name }}", |
| 69 | + "head": "update-version-${{ env.tag_name }}", |
57 | 70 | "base": "develop"
|
58 | 71 | }'
|
0 commit comments