@@ -15,70 +15,105 @@ jobs:
1515 uses : actions/checkout@v4
1616 with :
1717 fetch-depth : 0
18+ # submodules: "recursive"
19+
20+ - name : Safe submodule initialization
21+ run : |
22+ echo "Checking for submodules..."
23+ if [ -f .gitmodules ]; then
24+ if [ -s .gitmodules ]; then
25+ echo "Initializing submodules..."
26+ if git submodule sync --recursive 2>/dev/null; then
27+ git submodule update --init --force --recursive || {
28+ echo "Warning: Some submodules failed to initialize, continuing anyway..."
29+ }
30+ else
31+ echo "Warning: Submodule sync failed, continuing without submodules..."
32+ fi
33+ else
34+ echo ".gitmodules exists but is empty, skipping submodule initialization"
35+ fi
36+ else
37+ echo "No .gitmodules file found, no submodules to initialize"
38+ fi
1839
1940 # Step 2: Set up Git with official account
2041 - name : Set up Git
2142 run : |
22- git config user.name "github-actions[bot]"
23- git config user.email "github-actions[bot]@users.noreply.github.com"
43+ git config --global user.name "github-actions[bot]"
44+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
2445
2546 # Step 3: Check and delete existing tag
2647 - name : Check and delete existing tag
2748 run : |
2849 if git rev-parse ${{ env.TAG_VERSION }} >/dev/null 2>&1; then
29- git tag -d ${{ env.TAG_VERSION }} # Delete local tag
30- git push --delete origin ${{ env.TAG_VERSION }} # Delete remote tag
50+ git tag -d ${{ env.TAG_VERSION }}
51+ git push --delete origin ${{ env.TAG_VERSION }}
3152 fi
3253
3354 # Step 4: Update version file
3455 - name : Update version file
3556 run : |
36- echo "${{ env.TAG_VERSION }}" > version/version # Write the version to the file
57+ mkdir -p version
58+ echo -n "${{ env.TAG_VERSION }}" > version/version
3759
38- # Step 5: Commit and push changes to the correct branch
60+ # Step 5: Commit and push changes
3961 - name : Commit and push changes
4062 env :
4163 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4264 run : |
4365 git add version/version
4466 git commit -m "Update version to ${{ env.TAG_VERSION }}"
45- git push origin HEAD:${{ github.ref }} # Push to the current branch
4667
47- # Step 6: Create and push new tag
48- - name : Create and push tag
49- env :
50- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
68+ # Step 6: Update tag
69+ - name : Update tag
5170 run : |
52- git tag ${{ env.TAG_VERSION }} # Create new tag
53- git push origin ${{ env.TAG_VERSION }} # Push the tag
71+ git tag -fa ${{ env.TAG_VERSION }} -m "Update version to ${{ env.TAG_VERSION }}"
72+ git push origin ${{ env.TAG_VERSION }} --force
5473
5574 # Step 7: Find and Publish Draft Release
5675 - name : Find and Publish Draft Release
57- uses : actions/github-script@v6
76+ uses : actions/github-script@v7
5877 with :
5978 github-token : ${{ secrets.GITHUB_TOKEN }}
6079 script : |
61- // Get the list of releases
62- const releases = await github.rest.repos.listReleases({
63- owner: context.repo.owner,
64- repo: context.repo.repo
65- });
66-
67- // Find the draft release where the title and tag_name are the same
68- const draftRelease = releases.data.find(release =>
69- release.draft && release.name === release.tag_name
70- );
80+ const { owner, repo } = context.repo;
81+ const tagName = process.env.TAG_VERSION;
7182
72- if (draftRelease) {
73- // Publish the draft release using the release_id
83+ try {
84+ let release;
85+ try {
86+ const response = await github.rest.repos.getReleaseByTag({
87+ owner,
88+ repo,
89+ tag: tagName
90+ });
91+ release = response.data;
92+ } catch (tagError) {
93+ core.info(`Release not found by tag, searching all releases...`);
94+ const releases = await github.rest.repos.listReleases({
95+ owner,
96+ repo,
97+ per_page: 100
98+ });
99+
100+ release = releases.data.find(r => r.draft && r.tag_name === tagName);
101+ if (!release) {
102+ throw new Error(`No release found with tag ${tagName}`);
103+ }
104+ }
105+
74106 await github.rest.repos.updateRelease({
75- owner: context.repo.owner,
76- repo: context.repo.repo,
77- release_id: draftRelease.id, // Use release_id
78- draft: false
107+ owner,
108+ repo,
109+ release_id: release.id,
110+ draft: false,
111+ prerelease: release.prerelease
79112 });
80-
81- core.info(`Draft Release ${draftRelease.tag_name} published successfully.`);
82- } else {
83- core.info("No matching draft release found.");
84- }
113+
114+ const status = release.draft ? "was draft" : "was already published";
115+ core.info(`Release ${tagName} ensured to be published (${status}).`);
116+
117+ } catch (error) {
118+ core.warning(`Could not find or update release for tag ${tagName}: ${error.message}`);
119+ }
0 commit comments