variables: # Change these per repository BUILD_NAME: "multi-currency-switcher" OUT_DIR: "release-builds" stages: - test - build - release # ========================================================================= # PART 1: Merge into master - Build both variations + store them permanently # ========================================================================= compile_build: stage: build image: alpine:latest rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH before_script: - apk add --no-cache zip unzip rsync curl script: # ---- Work out release name from the merged MR's source branch ---- - | SOURCE_BRANCH=$(printf '%s' "$CI_COMMIT_TITLE" | sed -nE "s/^Merge branch '([^']+)' into.*/\1/p") if [ -z "$SOURCE_BRANCH" ]; then SOURCE_BRANCH="release-$CI_COMMIT_SHORT_SHA"; fi # Package registry versions can't contain "/" etc., so sanitise and append the SHA PACKAGE_VERSION="$(printf '%s' "$SOURCE_BRANCH" | tr -c 'A-Za-z0-9._-' '-')-$CI_COMMIT_SHORT_SHA" echo "Source branch: $SOURCE_BRANCH | Package version: $PACKAGE_VERSION" - echo "========== CLEANING WORKSPACE ==========" - rm -f bitbucket-pipelines.yml .gitignore .gitlab-ci.yml - rm -f phpcs.xml package.json package-lock.json - rm -f composer.json composer.lock postcss.config.js - rm -f .gitignore .semgrepignore plugin_brain.md webpack.config.js tailwind.config.js REVIEW.md - rm -rf vendor/bin vendor/dealerdirect vendor/phpcompatibility vendor/squizlabs vendor/woocommerce vendor/wp-coding-standards - rm -rf src tests - mkdir -p "$OUT_DIR" - echo "========== STARTING WOO BUILD (WITHOUT FREEMIUS) ==========" # Everything except the Freemius loader class - mkdir -p "/tmp/pkg-woo/$BUILD_NAME" - rsync -a --exclude='.*' --exclude="$OUT_DIR/" --exclude='/wc-currency-switcher-fs.php' ./ "/tmp/pkg-woo/$BUILD_NAME/" - (cd /tmp/pkg-woo && zip -rq "$CI_PROJECT_DIR/$OUT_DIR/${BUILD_NAME}.zip" "$BUILD_NAME") - rm -rf /tmp/pkg-woo - echo "========== UPLOADING BOTH BUILDS TO PACKAGE REGISTRY (permanent) ==========" - | for f in "${BUILD_NAME}.zip"; do curl --fail-with-body -sS \ --header "JOB-TOKEN: $CI_JOB_TOKEN" \ --upload-file "$OUT_DIR/$f" \ "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${BUILD_NAME}/${PACKAGE_VERSION}/${f}" echo done # Pass values to the release job - echo "SOURCE_BRANCH=$SOURCE_BRANCH" >> build.env - echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> build.env artifacts: paths: - release-builds/ expire_in: 7 days reports: dotenv: build.env # ========================================================================= # PART 3: Create the Release with both builds attached # ========================================================================= create_release: stage: release image: registry.gitlab.com/gitlab-org/cli:latest rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH needs: - job: compile_build artifacts: true script: - echo "Creating release v-$CI_COMMIT_SHORT_SHA for $SOURCE_BRANCH" release: name: "release $SOURCE_BRANCH" tag_name: "v-$CI_COMMIT_SHORT_SHA" ref: "$CI_COMMIT_SHA" description: "Production builds for ${BUILD_NAME} (from ${SOURCE_BRANCH})." assets: links: - name: "${BUILD_NAME}.zip" url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${BUILD_NAME}/${PACKAGE_VERSION}/${BUILD_NAME}.zip" link_type: package