Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Mercurial code with Git code #19

Merged
merged 6 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/commit-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Commit checker

on:
pull_request:

jobs:
commit-checker:
name: Commit checker
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 4

- name: Get pull-request commits
run: |
set -x
# actions/checkout did a merge checkout of the pull-request. As such, the first
# commit is the merge commit. This means that on HEAD^ is the base branch, and
# on HEAD^2 are the commits from the pull-request. We now check if those trees
# have a common parent. If not, we fetch a few more commits till we do. In result,
# the log between HEAD^ and HEAD^2 will be the commits in the pull-request.
DEPTH=4
while [ -z "$(git merge-base HEAD^ HEAD^2)" ]; do
git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --deepen=${DEPTH} origin HEAD
DEPTH=$(( ${DEPTH} * 4 ))
done

# Just to show which commits we are going to evaluate.
git log --oneline HEAD^..HEAD^2

- name: Checkout commit-checker
uses: actions/checkout@v2
with:
repository: OpenTTD/OpenTTD-git-hooks
path: git-hooks
ref: master

- name: Check commits
run: |
set -x
HOOKS_DIR=./git-hooks/hooks GIT_DIR=.git ./git-hooks/hooks/check-commits.sh HEAD^..HEAD^2
echo "Commit checks passed"

149 changes: 149 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
name: Publish binaries

on:
push:
tags:
- '*'
schedule:
- cron: '0 21 * * *'

jobs:
publish_binaries:
name: Publish binaries
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Checkout tags
uses: openttd/actions/checkout@v1
with:
with-tags: true

- name: Set variables
id: vars
run: |
set -e

FULL_VERSION=$(./findversion.sh)
RELEASE_DATE=$(TZ='UTC' date +"%Y-%m-%d %H:%M UTC")
VERSION=$(echo "${FULL_VERSION}" | cut -f 1 -d$'\t')

# If this secret is not set, we are doing a dryrun. This means that
# people who fork this repository will not try to publish this to AWS
# (as that will most likely fail anyway).
if [ -z "${{ secrets.CDN_S3_BUCKET }}" ]; then
DRY_RUN="true"
else
DRY_RUN="false"
fi

REPO_NAME=$(echo ${{ github.repository }} | cut -d/ -f2 | tr [A-Z] [a-z])
# If we run on "schedule", we are producting a nightly. Otherwise it
# is a tag, so a release.
if [ "${{ github.event_name }}" = "schedule" ]; then
FOLDER="${REPO_NAME}-nightlies"

# Download the latest version we published; if we are different, it
# is safe to assume we are newer.
LATEST_VERSION=$(curl --fail -s https://cdn.openttd.org/${FOLDER}/latest.yaml | grep version | cut -d: -f2 | cut -b 2-)

if [ "${LATEST_VERSION}" = "${VERSION}" ]; then
echo "Run on schedule; going to skip this run, as we already build this version"
SKIP="true"
elif [ "${DRY_RUN}" = "true" ]; then
# Also skip everything if we are triggered frm the schedule and we
# are a fork. That would waste a lot of CPU cycles for no good reason.
echo "Run on schedule; going to skip this run, as this is a fork"
SKIP="true"
else
SKIP="false"
fi
else
FOLDER="${REPO_NAME}-releases"
SKIP="false"
fi

echo "::set-output name=release-date::${RELEASE_DATE}"
echo "::set-output name=version::${VERSION}"
echo "::set-output name=folder::${FOLDER}"
echo "::set-output name=dry-run::${DRY_RUN}"
echo "::set-output name=skip::${SKIP}"

echo "Release-date: ${RELEASE_DATE}"
echo "Version: ${VERSION}"
echo "Folder: ${FOLDER}"
echo "Dry-run: ${DRY_RUN}"
echo "Skip: ${SKIP}"

- if: steps.vars.outputs.skip == 'false'
name: Install dependencies
run: |
set -e

sudo apt update
sudo apt install -y catcodec --no-install-recommends

- if: steps.vars.outputs.skip == 'false'
name: Build
run: |
set -e

make maintainer-clean
make bundle_zip bundle_xsrc

# Move bundles in their own folder
mkdir bundles
mv opensfx-${{ steps.vars.outputs.version }}-source.tar.xz bundles/
mv opensfx-${{ steps.vars.outputs.version }}-all.zip bundles/

- if: steps.vars.outputs.skip == 'false'
name: Create checksums
run: |
set -e

cd bundles
for i in $(ls); do
openssl dgst -r -md5 -hex $i > $i.md5sum
openssl dgst -r -sha1 -hex $i > $i.sha1sum
openssl dgst -r -sha256 -hex $i > $i.sha256sum
done

# Show the content of the bundles folder, to make problems debugging easier
ls -l

- if: steps.vars.outputs.skip == 'false'
name: Prepare bundles folder
run: |
set -e

echo "${{ steps.vars.outputs.release-date }}" > bundles/released.txt
cp docs/readme.txt bundles/
cp docs/changelog.txt bundles/

# Show the content of the bundles folder, to make problems debugging easier
ls -l bundles/

- if: steps.vars.outputs.dry-run == 'false' && steps.vars.outputs.skip == 'false'
name: Publish
id: publish
run: |
set -e

aws s3 cp --recursive --only-show-errors bundles/ s3://${{ secrets.CDN_S3_BUCKET }}/${{ steps.vars.outputs.folder }}/${{ steps.vars.outputs.version }}/
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- if: steps.vars.outputs.dry-run == 'false' && steps.vars.outputs.skip == 'false'
name: Trigger 'update CDN'
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.DEPLOYMENT_TOKEN }}
repository: OpenTTD/workflows
event-type: update-cdn
client-payload: '{"version": "${{ steps.vars.outputs.version }}", "folder": "${{ steps.vars.outputs.folder }}"}'

34 changes: 34 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Testing

on:
push:
branches:
- master
pull_request:

jobs:
build:
name: Build OpenSFX
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Checkout tags
uses: openttd/actions/checkout@v1
with:
with-tags: true
- name: Install dependencies
run: |
set -e

sudo apt update
sudo apt install -y catcodec --no-install-recommends
- name: Build
run: |
set -e

make maintainer-clean
make bundle_tar bundle_src

File renamed without changes.
68 changes: 29 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ SHELL := /bin/bash
##################################################################

# Definition of the grfs
REPO_NAME ?= My NewGRF
REPO_NAME ?= OpenSFX

# This is the filename part common to the grf file, main source file and the tar name
BASE_FILENAME ?= mynewgrf
BASE_FILENAME ?= opensfx

# Documentation files
DOC_FILES ?= docs/readme.txt docs/license.txt docs/changelog.txt
Expand Down Expand Up @@ -116,50 +116,41 @@ AWK ?= awk

GREP ?= grep

HG ?= $(shell hg st >/dev/null 2>/dev/null && which hg 2>/dev/null)
GIT ?= $(shell git status >/dev/null 2>/dev/null && which git 2>/dev/null)

PYTHON ?= python

UNIX2DOS ?= $(shell which unix2dos 2>/dev/null)
UNIX2DOS_FLAGS ?= $(shell [ -n $(UNIX2DOS) ] && $(UNIX2DOS) -q --version 2>/dev/null && echo "-q" || echo "")
UNIX2DOS_FLAGS ?= $(shell [ -n $(UNIX2DOS) ] && $(UNIX2DOS) -q --version 1>&2 2>/dev/null && echo "-q" || echo "")

################################################################
# Get the Repository revision, tags and the modified status
# The displayed name within OpenTTD / TTDPatch
# Looks like either
# a nightly build: GRF's Name nightly-r51
# a release build (taged version): GRF's Name 0.1
#
# Working copy / bundle version detection.
#
################################################################
# This must be conditional declarations, or building from the tar.gz won't work anymore
DEFAULT_BRANCH_NAME ?=

# HG revision
REPO_REVISION ?= $(shell $(HG) id -n | cut -d+ -f1)

# HG Hash
REPO_HASH ?= $(shell $(HG) id -i | cut -d+ -f1)

# Days of commit since 2000-1-1 00-00
REPO_DATE ?= $(shell $(HG) log -r$(REPO_HASH) --template='{time|shortdate}')
REPO_DAYS_SINCE_2000 ?= $(shell $(PYTHON) -c "from datetime import date; print (date(`echo "$(REPO_DATE)" | sed s/-/,/g | sed s/,0/,/g`)-date(2000,1,1)).days")

# Whether there are local changes
REPO_MODIFIED ?= $(shell [ "`$(HG) id | cut -c13`" = "+" ] && echo "M" || echo "")
# Always run version detection, so we always have an accurate modified
# flag
REPO_VERSIONS := $(shell AWK="$(AWK)" "./findversion.sh")

# Branch name
REPO_BRANCH ?= $(shell $(HG) id -b | sed "s/default/$(DEFAULT_BRANCH_NAME)/")
# Use autodetected revisions
REPO_VERSION ?= $(shell echo "$(REPO_VERSIONS)" | cut -f 1 -d' ')
REPO_DATE ?= $(shell echo "$(REPO_VERSIONS)" | cut -f 2 -d' ')
REPO_HASH ?= $(shell echo "$(REPO_VERSIONS)" | cut -f 4 -d' ')

# Any tag which is not 'tip'
REPO_TAGS ?= $(shell $(HG) id -t | grep -v "tip")
# Days of commit since 2000-01-01. REPO_DATE is in format YYYYMMDD.
REPO_DATE_YEAR := $(shell echo "${REPO_DATE}" | cut -b1-4)
REPO_DATE_MONTH := $(shell echo "${REPO_DATE}" | cut -b5-6 | sed s/^0//)
REPO_DATE_DAY := $(shell echo "${REPO_DATE}" | cut -b7-8 | sed s/^0//)
REPO_DAYS_SINCE_2000 := $(shell $(PYTHON) -c "from datetime import date; print( (date($(REPO_DATE_YEAR),$(REPO_DATE_MONTH),$(REPO_DATE_DAY))-date(2000,1,1)).days)")

# Filename addition, if we're not building the default branch
REPO_BRANCH_STRING ?= $(shell if [ "$(REPO_BRANCH)" = "$(DEFAULT_BRANCH_NAME)" ]; then echo ""; else echo "-$(REPO_BRANCH)"; fi)
REPO_TAGS ?= $(REPO_VERSION)

# The version reported to OpenTTD. Usually days since 2000 + branch offset
NEWGRF_VERSION ?= $(shell let x="$(REPO_DAYS_SINCE_2000) + 65536 * $(REPO_BRANCH_VERSION)"; echo "$$x")

# The shown version is either a tag, or in the absence of a tag the revision.
REPO_VERSION_STRING ?= $(shell [ -n "$(REPO_TAGS)" ] && echo $(REPO_TAGS)$(REPO_MODIFIED) || echo $(REPO_DATE)$(REPO_BRANCH_STRING) \($(NEWGRF_VERSION):$(REPO_HASH)$(REPO_MODIFIED)\))
REPO_VERSION_STRING ?= $(shell [ -n "$(REPO_TAGS)" ] && echo $(REPO_TAGS) || echo $(REPO_DATE)$(REPO_BRANCH_STRING) \($(NEWGRF_VERSION):$(REPO_HASH)\))

# The title consists of name and version
REPO_TITLE ?= $(REPO_NAME) $(REPO_VERSION_STRING)
Expand Down Expand Up @@ -349,7 +340,7 @@ GRFID_FLAGS ?= -m
# followed by an M, if the source repository is not a clean version.

# Common to all filenames
FILE_VERSION_STRING ?= $(shell [ -n "$(REPO_TAGS)" ] && echo "$(REPO_TAGS)$(REPO_MODIFIED)" || echo "$(REPO_BRANCH_STRING)$(NEWGRF_VERSION)$(REPO_MODIFIED)")
FILE_VERSION_STRING ?= $(shell [ -n "$(REPO_TAGS)" ] && echo "$(REPO_TAGS)" || echo "$(REPO_BRANCH_STRING)$(NEWGRF_VERSION)")
DIR_NAME := $(shell [ -n "$(REPO_TAGS)" ] && echo $(BASE_FILENAME)-$(FILE_VERSION_STRING) || echo $(BASE_FILENAME))
VERSIONED_FILENAME := $(BASE_FILENAME)-$(FILE_VERSION_STRING)
DIR_NAME_SRC := $(VERSIONED_FILENAME)-source
Expand All @@ -358,7 +349,7 @@ TAR_FILENAME := $(DIR_NAME).tar
BZIP_FILENAME := $(TAR_FILENAME).bz2
GZIP_FILENAME := $(TAR_FILENAME).gz
XZ_FILENAME := $(TAR_FILENAME).xz
ZIP_FILENAME := $(VERSIONED_FILENAME).zip
ZIP_FILENAME := $(VERSIONED_FILENAME)-all.zip
MD5_FILENAME := $(DIR_NAME).md5
MD5_SRC_FILENAME ?= $(DIR_NAME).check.md5

Expand Down Expand Up @@ -410,7 +401,7 @@ clean::
# Bundle source targets
# target 'bundle_src which builds source bundle
################################################################
RE_FILES_NO_SRC_BUNDLE = ^.devzone|^.hg
RE_FILES_NO_SRC_BUNDLE = ^.devzone|^.git

check: $(MD5_FILENAME)
$(_V) if [ -f $(MD5_SRC_FILENAME) ]; then echo "[CHECKING md5sums]"; else echo "Required file '$(MD5_SRC_FILENAME)' which to test against not found!"; false; fi
Expand All @@ -419,7 +410,7 @@ check: $(MD5_FILENAME)

$(DIR_NAME_SRC).tar: $(DIR_NAME_SRC)
$(_E) "[BUNDLE SRC]"
$(_V) $(HG) archive -t tar $<.tar
$(_V) $(GIT) archive --format=tar HEAD | tar -x -C $(DIR_NAME_SRC)
$(_V) $(TAR) -uf $@ $^

bundle_src: $(DIR_NAME_SRC).tar
Expand All @@ -435,19 +426,18 @@ Makefile.fordist:
$(_V) echo '# Definitions needed for tar releases' >> $@
$(_V) echo '# This part is automatically generated' >> $@
$(_V) echo '################################################################' >> $@
$(_V) echo 'REPO_VERSION := $(REPO_VERSION)' >> $@
$(_V) echo 'REPO_REVISION := $(NEWGRF_VERSION)' >> $@
$(_V) echo 'NEWGRF_VERSION := $(NEWGRF_VERSION)' >> $@
$(_V) echo 'REPO_HASH := $(REPO_HASH)' >> $@
$(_V) echo 'REPO_VERSION_STRING := $(REPO_VERSION_STRING)' >> $@
$(_V) echo 'REPO_TITLE := $(REPO_TITLE)' >> $@
$(_V) echo 'REPO_DATE := $(REPO_DATE)' >> $@
$(_V) echo 'REPO_BRANCH := $(REPO_BRANCH)' >> $@
$(_V) echo 'REPO_MODIFIED := $(REPO_MODIFIED)' >> $@
$(_V) echo 'REPO_TAGS := $(REPO_TAGS)' >> $@
$(_V) echo 'HG := :' >> $@
$(_V) echo 'GIT := :' >> $@
$(_V) echo 'PYTHON := :' >> $@

ifneq ("$(strip $(HG))",":")
ifneq ("$(strip $(GIT))",":")
$(DIR_NAME_SRC): $(MD5_SRC_FILENAME) Makefile.fordist
$(_E) "[ASSEMBLING] $(DIR_NAME_SRC)"
$(_V)-rm -rf $@
Expand All @@ -456,7 +446,7 @@ $(DIR_NAME_SRC): $(MD5_SRC_FILENAME) Makefile.fordist
$(_V) cp $(CP_FLAGS) Makefile.fordist $@/Makefile.dist
else
$(DIR_NAME_SRC):
$(_E) "Source releases can only be made from a hg checkout."
$(_E) "Source releases can only be made from a git checkout."
$(_V) false
endif

Expand Down
2 changes: 1 addition & 1 deletion Makefile.local.sample
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
# BZIP = bzip2
# CC = gcc
# AWK = awk
# HG = hg
# GIT = git
# MAKE = make
# UNIX2DOS = $(shell [ `which unix2dos 2>/dev/null` ] && echo "unix2dos" || echo "")
# MD5SUM = $(shell [ "$(OSTYPE)" = "Darwin" ] && echo "md5 -r" || echo "md5sum")
Expand Down
Loading