|
| 1 | +name: 🚀 Automatic Release |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + types: [closed] |
| 8 | + |
| 9 | +env: |
| 10 | + SUPPORTED_SERVER_VERSIONS: "1.4-b8 1.3-b9" # space-delimited |
| 11 | + SUBFOLDER: ${{ github.event.repository.name }} |
| 12 | + PROJECT_FOLDER: src |
| 13 | + |
| 14 | +jobs: |
| 15 | + release: |
| 16 | + if: ${{ github.event.pull_request.merged }} |
| 17 | + runs-on: ubuntu-22.04 |
| 18 | + permissions: |
| 19 | + contents: write |
| 20 | + steps: |
| 21 | + - name: 🚚 Checkout repository |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: 🔍 Inspect contents |
| 25 | + run: | |
| 26 | + version=$(sed -n '/Version/{s/.*<Version value=\"\(.*\)\"[ ]*\/>.*/\1/;p}' ModInfo.xml) |
| 27 | + if gh release view "$version" > /dev/null 2>&1; then |
| 28 | + echo "Release $version already exists; please update ModInfo.xml and create another pull request" |
| 29 | + exit 1 |
| 30 | + fi |
| 31 | + echo "MOD_VERSION=$version" >> $GITHUB_ENV |
| 32 | +
|
| 33 | + prerelease=$([[ $version = 0* ]] && echo "true" || echo "false") |
| 34 | + echo "PRERELEASE=$prerelease" >> $GITHUB_ENV |
| 35 | + |
| 36 | + csproj_path=$(sed -n 's/.*"[^"]*\\\([^"]*\.csproj\)".*/\1/p' ${{ github.event.repository.name }}.sln) |
| 37 | + echo "CSPROJ_NAME=$csproj_path" >> $GITHUB_ENV |
| 38 | + |
| 39 | + dll_name=$(sed -n '/AssemblyName/{s/.*<AssemblyName>\(.*\)<\/AssemblyName>.*/\1/;p}' ${{ env.PROJECT_FOLDER }}/$csproj_path) |
| 40 | + echo "DLL_NAME=$dll_name" >> $GITHUB_ENV |
| 41 | +
|
| 42 | + - name: 🚛 Checkout 7dtd-references |
| 43 | + uses: actions/checkout@v4 |
| 44 | + with: |
| 45 | + repository: "${{ github.repository_owner }}/7dtd-references" |
| 46 | + token: "${{ secrets.REFERENCES_TOKEN }}" |
| 47 | + path: "7dtd-references" |
| 48 | + |
| 49 | + - name: 🧐 Install mono |
| 50 | + run: | |
| 51 | + sudo apt-get update |
| 52 | + sudo apt-get install -y mono-complete |
| 53 | +
|
| 54 | + - name: 🛻 Restore NuGet packages |
| 55 | + run: | |
| 56 | + nuget restore ${{ github.event.repository.name }}.sln |
| 57 | +
|
| 58 | + - name: 📦 Build and package artifacts |
| 59 | + run: | |
| 60 | + cp ${{ env.PROJECT_FOLDER }}/ModApi.cs ${{ env.PROJECT_FOLDER }}/ModApi.cs.bak |
| 61 | + for GAME_VERSION in ${{ env.SUPPORTED_SERVER_VERSIONS }}; do |
| 62 | + echo "building and packing mod for 7DTD version $GAME_VERSION" |
| 63 | +
|
| 64 | + # update release and target versions |
| 65 | + cp ${{ env.PROJECT_FOLDER }}/ModApi.cs.bak ${{ env.PROJECT_FOLDER }}/ModApi.cs |
| 66 | + sed -i "s|DLL_VERSION = \"test-version\"|DLL_VERSION = \"${{ env.MOD_VERSION }}\"|g" ${{ env.PROJECT_FOLDER }}/ModApi.cs |
| 67 | + sed -i "s|BUILD_TARGET = \"test-target\"|BUILD_TARGET = \"$GAME_VERSION\"|g" ${{ env.PROJECT_FOLDER }}/ModApi.cs |
| 68 | +
|
| 69 | + # TODO: update assembly info |
| 70 | + |
| 71 | +
|
| 72 | + # update reference paths |
| 73 | + sed -i "s|<HintPath>..\\\\..\\\\..\\\\..\\\\..\\\\..\\\\Program Files (x86)\\\\Steam\\\\steamapps\\\\common\\\\7 Days to Die Dedicated Server|<HintPath>..\\\\7dtd-references\\\\${GAME_VERSION}|g" ${{ env.PROJECT_FOLDER }}/${{ env.CSPROJ_NAME }} |
| 74 | +
|
| 75 | + # uncomment if troubleshooting becomes necessary |
| 76 | + # echo "${{ env.PROJECT_FOLDER }}/${{ env.CSPROJ_NAME }} references were modified to the following:" |
| 77 | + # cat "${{ env.PROJECT_FOLDER }}/${{ env.CSPROJ_NAME }}" |
| 78 | +
|
| 79 | + msbuild ${{ github.event.repository.name }}.sln /p:Configuration=Release |
| 80 | + if [ $? -ne 0 ]; then |
| 81 | + echo "build for $GAME_VERSION failed and will be skipped" |
| 82 | + continue |
| 83 | + else |
| 84 | + echo "build for $GAME_VERSION was successful" |
| 85 | + fi |
| 86 | +
|
| 87 | + mkdir "${{ env.SUBFOLDER }}" |
| 88 | + cp -r Config "${{ env.SUBFOLDER }}/" |
| 89 | + cp ModInfo.xml "${{ env.SUBFOLDER }}/" |
| 90 | + cp README.md "${{ env.SUBFOLDER }}/" |
| 91 | + cp CHANGELOG.md "${{ env.SUBFOLDER }}/" |
| 92 | + cp "${{ env.DLL_NAME }}.dll" "${{ env.SUBFOLDER }}/" |
| 93 | + zip -r "${{ github.event.repository.name }}-${{ env.MOD_VERSION }}-7dtd-$GAME_VERSION.zip" "${{ env.SUBFOLDER }}" |
| 94 | + rm -rf "${{ env.SUBFOLDER }}" |
| 95 | + done |
| 96 | + if ! ls *.zip > /dev/null 2>&1; then |
| 97 | + echo "could not successfully build for any of the supported versions of 7 days to die" |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | +
|
| 101 | + - name: 📰 Post new release |
| 102 | + uses: ncipollo/release-action@v1 |
| 103 | + with: |
| 104 | + tag: ${{ env.MOD_VERSION }} |
| 105 | + commit: main |
| 106 | + name: ${{ github.event.pull_request.title }} |
| 107 | + body: ${{ github.event.pull_request.body }} |
| 108 | + generateReleaseNotes: true |
| 109 | + artifacts: "*.zip" |
| 110 | + prerelease: ${{ env.PRERELEASE }} |
| 111 | + # if you'd like to review the generated release before publishing it, enable draft mode |
| 112 | + # draft: true |
0 commit comments