7 value: ${{ jobs.source.outputs.version }}
9 value: ${{ jobs.source.outputs.is_tag }}
11 value: ${{ jobs.source.outputs.trigger_type }}
13 value: ${{ jobs.source.outputs.folder }}
15 value: ${{ jobs.source.outputs.survey_key }}
21 runs-on: ubuntu-latest
24 version: ${{ steps.metadata.outputs.version }}
25 is_tag: ${{ steps.metadata.outputs.is_tag }}
26 trigger_type: ${{ steps.metadata.outputs.trigger_type }}
27 folder: ${{ steps.metadata.outputs.folder }}
28 survey_key: ${{ steps.survey_key.outputs.survey_key }}
31 - name: Checkout (Release)
32 if: github.event_name == 'release'
33 uses: actions/checkout@v4
35 # We generate a changelog; for this we need the full git log.
38 - name: Checkout (Manual)
39 if: github.event_name == 'workflow_dispatch'
40 uses: actions/checkout@v4
42 ref: ${{ github.event.inputs.ref }}
43 # We generate a changelog; for this we need the full git log.
46 - name: Checkout (Trigger)
47 if: github.event_name == 'repository_dispatch'
48 uses: actions/checkout@v4
50 ref: ${{ github.event.client_payload.ref }}
51 # We generate a changelog; for this we need the full git log.
54 - name: Check valid branch name
56 if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
57 REF="${{ github.event.inputs.ref }}"
58 elif [ "${{ github.event_name }}" = "repository_dispatch" ]; then
59 REF="${{ github.event.client_payload.ref }}"
61 REF="${{ github.ref }}"
64 # Check if we are a tag.
65 if [ -n "$(git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || false)" ]; then
69 # Check if the checkout caused the branch to be named.
70 if [ "$(git rev-parse --abbrev-ref HEAD)" != "HEAD" ]; then
74 # Check if this was a pull request.
75 if [ -n "$(echo ${REF} | grep '^refs/pull/[0-9]*')" ]; then
76 PULL=$(echo ${REF} | cut -d/ -f3)
77 git checkout -b pr${PULL}
80 # Are we still in a detached state? Error out.
81 if [ "$(git rev-parse --abbrev-ref HEAD)" == "HEAD" ]; then
82 echo "The 'ref' given resulted in a checkout of a detached HEAD."
83 echo "We cannot detect the version for these checkout accurate."
85 echo "If you want to build a Pull Request, make sure you use 'refs/pull/NNN/head'."
87 echo "Cancelling build, as without a version we cannot store the artifacts."
91 - name: Generate metadata
95 echo "::group::Prepare metadata files"
96 cmake -DGENERATE_OTTDREV=1 -P cmake/scripts/FindVersion.cmake
97 TZ='UTC' date +"%Y-%m-%d %H:%M UTC" > .release_date
98 cat .ottdrev | cut -f 1 -d$'\t' > .version
100 if [ $(cat .ottdrev | cut -f 5 -d$'\t') = '1' ]; then
101 # Assume that all tags are always releases. Why else make a tag?
104 FOLDER="${{ env.FOLDER_RELEASES }}"
105 TRIGGER_TYPE="new-tag"
107 python3 ./.github/changelog.py "$(cat .version)" > .changelog
111 BRANCH=$(git symbolic-ref -q HEAD | sed 's@.*/@@')
112 if [ -z "${BRANCH}" ]; then
113 echo "Internal error: branch name is empty."
114 echo "An earlier step should have prevented this from happening."
115 echo "Cancelling build, as without a branch name we cannot store the artifacts"
119 if [ "${BRANCH}" = "${{ env.NIGHTLIES_BRANCH }}" ]; then
120 # The "master" branch is special, and we call a nightly.
121 FOLDER="${{ env.FOLDER_NIGHTLIES }}/$(date +%Y)"
122 TRIGGER_TYPE="new-master"
124 # All other branches, which can be builds of Pull Requests, are
125 # put in their own folder.
126 FOLDER="${{ env.FOLDER_BRANCHES }}/${BRANCH}"
127 TRIGGER_TYPE="new-branch"
130 # For nightlies / branches, use the git log of the last 7 days as changelog.
131 revdate=$(git log -1 --pretty=format:"%ci")
132 last_week=$(date -d "$revdate -7days" +"%Y-%m-%d %H:%M")
133 echo "## Version $(cat .version) - changes since ${last_week}" > .changelog
134 echo "" >> .changelog
135 git log --oneline --after="${last_week}" >> .changelog
138 mkdir -p build/bundles
139 cp .changelog build/bundles/changelog.md
140 cp .release_date build/bundles/released.txt
141 cp README.md build/bundles/README.md
144 echo "Release Date: $(cat .release_date)"
145 echo "Revision: $(cat .ottdrev)"
146 echo "Version: $(cat .version)"
147 echo "Is tag: ${IS_TAG}"
148 echo "Folder on CDN: ${FOLDER}"
149 echo "Workflow trigger: ${TRIGGER_TYPE}"
151 echo "version=$(cat .version)" >> $GITHUB_OUTPUT
152 echo "is_tag=${IS_TAG}" >> $GITHUB_OUTPUT
153 echo "folder=${FOLDER}" >> $GITHUB_OUTPUT
154 echo "trigger_type=${TRIGGER_TYPE}" >> $GITHUB_OUTPUT
156 NIGHTLIES_BRANCH: master
157 FOLDER_RELEASES: openttd-releases
158 FOLDER_NIGHTLIES: openttd-nightlies
159 FOLDER_BRANCHES: openttd-branches
161 - name: Generate survey key
164 if [ -z "${{ vars.SURVEY_TYPE }}" ]; then
165 echo "SURVEY_TYPE variable not found; most likely running in a fork. Skipping step."
168 PAYLOAD='{"version":"${{ steps.metadata.outputs.version }}","type":"${{ vars.SURVEY_TYPE }}"}'
170 echo "${{ secrets.SURVEY_SIGNING_KEY }}" > survey_signing_key.pem
171 SIGNATURE=$(echo -n "${PAYLOAD}" | openssl dgst -sha256 -sign survey_signing_key.pem | base64 -w0)
172 rm -f survey_signing_key.pem
174 SURVEY_KEY=$(curl -f -s -X POST -d "${PAYLOAD}" -H "Content-Type: application/json" -H "X-Signature: ${SIGNATURE}" https://survey-participate.openttd.org/create-survey-key/${{ vars.SURVEY_TYPE }})
177 echo "survey_key=${SURVEY_KEY}" >> $GITHUB_OUTPUT
179 - name: Remove VCS information
183 - name: Create bundles
185 FOLDER_NAME=openttd-${{ steps.metadata.outputs.version }}
187 # Rename the folder to openttd-NNN
189 find . -maxdepth 1 -not -name . -not -name build -not -name ${FOLDER_NAME} -exec mv {} ${FOLDER_NAME}/ \;
191 echo "::group::Create tarball (xz) bundle"
192 tar --xz -cvf build/bundles/${FOLDER_NAME}-source.tar.xz ${FOLDER_NAME}
195 # This tarball is only to be used within this workflow.
196 echo "::group::Create tarball (gz) bundle"
197 tar --gzip -cvf source.tar.gz ${FOLDER_NAME}
200 echo "::group::Create zip bundle"
201 zip -9 -r build/bundles/${FOLDER_NAME}-source.zip ${FOLDER_NAME}
204 - name: Store bundles
205 uses: actions/upload-artifact@v4
208 path: build/bundles/*
211 - name: Store source (for other jobs)
212 uses: actions/upload-artifact@v4
214 name: internal-source