From df8c9b4b318ed043030d076ee58393bf5d704f80 Mon Sep 17 00:00:00 2001 From: Sebastian Ehlert <28669218+awvwgk@users.noreply.github.com> Date: Mon, 13 Sep 2021 16:45:55 +0200 Subject: Add workflow to create source releases (#563) - add release workflow to generate source archives - add workflow and script to automatically create single source file --- .github/workflows/release.yml | 129 ++++++++++++++++++++++++++++++++++++++++++ ci/single-file-gfortran.sh | 11 ++++ ci/single-file.patch | 29 ++++++++++ 3 files changed, 169 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100755 ci/single-file-gfortran.sh create mode 100644 ci/single-file.patch diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a3c5259 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,129 @@ +name: Release + +on: + push: + pull_request: + release: + types: [published] + +jobs: + source-archive: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + format: [zip] + env: + FORMAT: ${{ matrix.format }} + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Get version number + run: | + VERSION=$(git describe --tags --match 'v*' --always | tr -d 'v') + echo "VERSION=${VERSION}" >> $GITHUB_ENV + + - name: Create archive + run: | + echo "OUTPUT=${{ env.OUTPUT }}" >> $GITHUB_ENV + git archive --prefix ${{ env.PREFIX }} --format ${{ env.FORMAT }} HEAD > ${{ env.OUTPUT }} + env: + OUTPUT: fpm-${{ env.VERSION }}.${{ env.FORMAT }} + PREFIX: fpm-${{ env.VERSION }}/ + + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: ${{ env.OUTPUT }} + path: ${{ env.OUTPUT }} + + source-single-file: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Get version number + run: | + VERSION=$(git describe --tags --match 'v*' --always | tr -d 'v') + echo "VERSION=${VERSION}" >> $GITHUB_ENV + + # Note: this step is meant to remove the test targets from the package manifest, + # a change in the package manifest might require to regenerate the patch file. + - name: Remove tests + run: | + patch -p1 < ./ci/single-file.patch + + - name: Install fpm + uses: fortran-lang/setup-fpm@v3 + with: + fpm-version: 'v0.4.0' + + - name: Create single file version + run: | + echo "OUTPUT=${{ env.OUTPUT }}" >> $GITHUB_ENV + echo "#define FPM_BOOTSTRAP" > fpm-${{ env.VERSION }}.F90 + fpm build --compiler ./ci/single-file-gfortran.sh + env: + OUTPUT: fpm-${{ env.VERSION }}.F90 + OMP_NUM_THREADS: 1 + + # Building the bootstrap version from the single source version is the most expensive + # step in this workflow, since we have to compile several thousand lines of source. + - name: Build single source version + run: | + echo "EXE=${{ env.BUILD_DIR }}/fpm" >> $GITHUB_ENV + mkdir ${{ env.BUILD_DIR }} + gfortran ${{ env.OUTPUT }} -J ${{ env.BUILD_DIR }} -o ${{ env.BUILD_DIR }}/fpm + env: + BUILD_DIR: build/bootstrap + + - name: Undo patch + run: | + patch -p1 -R < ./ci/single-file.patch + + - name: Build fpm with bootstrap version + run: | + ${{ env.EXE }} build + + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: ${{ env.OUTPUT }} + path: ${{ env.OUTPUT }} + + upload-artifacts: + if: github.event_name == 'release' + runs-on: ubuntu-latest + needs: + - source-archive + - source-single-file + + steps: + - name: Download Artifacts + uses: actions/download-artifact@v2 + with: + path: ${{ github.workspace }} # This will download all files + + - name: Create SHA256 checksums + run: | + for output in fpm-*/fpm-*; do + pushd $(dirname "$output") + sha256sum $(basename "$output") | tee $(basename "$output").sha256 + popd + done + + - name: Upload assets + if: ${{ github.event_name == 'release' }} + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: fpm-*/fpm-* + file_glob: true + tag: ${{ github.ref }} + overwrite: true diff --git a/ci/single-file-gfortran.sh b/ci/single-file-gfortran.sh new file mode 100755 index 0000000..904c7f8 --- /dev/null +++ b/ci/single-file-gfortran.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +output="${OUTPUT:-fpm-single-file.F90}" + +args=("$@") +file=$(printf "%s\n" "${args[@]}" | grep -P '^.+\.[fF]90$') +if [ $? = 0 ]; then + echo " + Appending source file '$file' to '${output}'" + cat $file >> "${output}" +fi +exec gfortran "${args[@]}" diff --git a/ci/single-file.patch b/ci/single-file.patch new file mode 100644 index 0000000..7980a7a --- /dev/null +++ b/ci/single-file.patch @@ -0,0 +1,29 @@ +diff --git a/fpm.toml b/fpm.toml +index 12ec05aa..20425dfd 100644 +--- a/fpm.toml ++++ b/fpm.toml +@@ -14,22 +14,5 @@ rev = "2f5eaba864ff630ba0c3791126a3f811b6e437f3" + git = "https://github.com/urbanjost/M_CLI2.git" + rev = "ea6bbffc1c2fb0885e994d37ccf0029c99b19f24" + +-[[test]] +-name = "cli-test" +-source-dir = "test/cli_test" +-main = "cli_test.f90" +- +-[[test]] +-name = "new-test" +-source-dir = "test/new_test" +-main = "new_test.f90" +- +-[[test]] +-name = "fpm-test" +-source-dir = "test/fpm_test" +-main = "main.f90" +- +-[[test]] +-name = "help-test" +-source-dir = "test/help_test" +-main = "help_test.f90" ++[build] ++auto-tests = false -- cgit v1.2.3